My class is extending the EventDispatcher class.
Here's a snippet of the class:
package com.superbokbok.irisreader
{
import com.adobe.xml.syndication.generic.*;
import flash.events.EventDispatcher;
import mx.collections.ArrayCollection;
import mx.events.PropertyChangeEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;
[Bindable]
public class Subscription extends EventDispatcher
{
private var _feedURL:String;
private var _title:String;
private var _url:String;
private var _articles:ArrayCollection;
private var _lastChecked:Date;
private var _service:HTTPService;
public function Subscription(feedURL:String)
{
_feedURL = feedURL;
_articles = new ArrayCollection();
_service = new HTTPService();
_service.url = _feedURL;
_service.resultFormat = HTTPService.RESULT_FORMAT_E4X;
_service.addEventListener(ResultEvent.RESULT,
onServiceResult);
_service.addEventListener(FaultEvent.FAULT, onServiceFault);
refresh();
}
private function onServiceResult(event:ResultEvent):void
{
var feed:IFeed = FeedFactory.getFeedByXML(event.result as
XML);
setTitle(feed.metadata.title);
setURL(feed.metadata.link);
for each (var item:IItem in feed.items)
{
if (lastChecked == null || item.date.getTime() >
lastChecked.getTime())
{
articles.addItem(item);
}
}
setLastChecked(new Date());
}
private function onServiceFault(event:FaultEvent):void
{
trace('error');
}
/**
* notifyPropertyChange
*
*/
private function
notifyPropertyChange(name:String,oldValue:Object,value:Object):void
{
if (value !== oldValue)
{
/**
//new event that doesn't work either
var event:PropertyChangeEvent = new
PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE,
true,false,"update",name,oldValue,value,this);
dispatchEvent(event); */
dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, name,
oldValue, value));
}
}
public function refresh():void {
_service.send();
}
public function get feedURL():String
{
return _feedURL;
}
private function setFeedURL(value:String):void
{
var oldValue:Object = _feedURL;
_feedURL = value;
notifyPropertyChange("feedURL", oldValue, value);
}
public function get lastChecked():Date
{
return _lastChecked;
}
private function setLastChecked(value:Date):void
{
var oldValue:Object = _lastChecked;
_lastChecked = value;
notifyPropertyChange("lastChecked", oldValue, value);
}
}
}
--- In [email protected], "Amy" <[EMAIL PROTECTED]> wrote:
>
> --- In [email protected], "superbokbok" superbokbok@
> wrote:
> >
> > Yes I thought that would fix the problem so I tried implementing
> this
> > within the
> > function notifyPropertyChange method
> > private function
> > notifyPropertyChange(name:String,oldValue:Object,value:Object):void
> > {
> > if (value !== oldValue)
> > {
> > var event:PropertyChangeEvent = new
> > PropertyChangeEvent(PropertyChangeEvent.PROPERTY_CHANGE,
> > true,false,"update",name,oldValue,value,this);
> > dispatchEvent(event);
> > }
> > }
> >
> > Now in the main.mxml file, I've set the listener like this:
> > this.addEventListener
> (PropertyChangeEvent.PROPERTY_CHANGE,testTrace,true\
> > );
> >
> > I can never seem to get this event to be recognized by the
> application.
> >
> > For reference, this notifyPropertyChange method is contained within
> an
> > AS class that fires the event when a Timer event fires after 1
> minute.
> > At this point, a new Date object is created, compared with the old
> date
> > value and fires the notifyPropertyChange method, to update the
> onscreen
> > time display.
> > If I register a listener with the target, then I can receive the
> event.
> > But I cannot seem to get any event, particularly the PROPERTY_CHANGE
> > event, which is what I want.
> >
> > I'd love to be able to use the propertychangeevent cuz it seems
> like a
> > nice, subtle way to be alerted of changes to an instance's
> variable. Any
> > suggestions on how to use the PropertyChangeEvent properly?? :)
> > regards
>
> What class is your class extending?
> -Amy
>