Hi Folks,
I'm currently working on a twitter AIR client using the twitterscript AS3
library and having some issues with bubbling custom events that are created by
nested "classses" back to the main application.
I've architected so that the main application (A) spawns a new timeline window
(B) for every twitter account a user may have. I have a Comm class (C) i use
as a DAO layer to decouple the twitterscript custom events from my framework
(in case i switch to a different as3 API library)
My custom event class looks like this
package com.kubeworks.events
{
import flash.events.Event;
public class TweetCommEvent extends Event
{
public static const TIMELINE_BACK:String = "timelineBack";
public static const STATUS_BACK:String = "statusBack";
public static const USER_INFO_BACK:String = "userInfoBack";
public static const RATE_LIMIT_STATUS:String = "rateLimitBack";
public var data : Object = new Object ();
public function TweetCommEvent(type:String,
bubbles:Boolean=true, cancelable:Boolean=false)
{
super(type, bubbles, cancelable);
}
override public function clone():Event {
return new PreferencePaneEvent(type, bubbles,
cancelable);
}
}
}
My Comm Class goes something like
package com.kubeworks.data
{
// Twitter API calls
import com.kubeworks.events.TweetCommEvent;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.utils.*;
import mx.utils.ObjectUtil;
import twitter.api.Twitter;
import twitter.api.events.TwitterEvent;
public class TweetComm extends EventDispatcher
{
private var username:String;
private var password:String;
private var _twitterClient:Twitter;
// Constructor
public function TweetComm(usern:String, pass:String)
{
// Initialize Twitter Event Listeners
_twitterClient = new Twitter();
_twitterClient.addEventListener(Event.ACTIVATE,
twitterClientActivateHandler);
_twitterClient.addEventListener(Event.DEACTIVATE,
twitterClientDeactivate);
_twitterClient.addEventListener(TwitterEvent.ON_FRIENDS_TIMELINE_RESULT,
twitterTimelineBack);
_twitterClient.addEventListener(TwitterEvent.ON_SET_STATUS, twitterStatusBack);
_twitterClient.addEventListener(TwitterEvent.ON_SHOW_INFO, twitterUserBack);
_twitterClient.addEventListener(TwitterEvent.ON_RATE_LIMIT_STATUS,
twitterRateLimitBackHandler);
// Do stuff
setLogin(usern, pass);
setAuth();
}
and within that class i'm re-dispatching like:
private function twitterRateLimitBackHandler(event:TwitterEvent):void {
var eventObj:TweetCommEvent = new
TweetCommEvent(TweetCommEvent.RATE_LIMIT_STATUS, true);
eventObj.data = event.data;
dispatchEvent(eventObj);
trace(">>twitterRateLimitBackHandler");
trace(ObjectUtil.toString(event));
trace("<<twitterRateLimitBackHandler");
trace(ObjectUtil.toString(eventObj));
}
I've set the bubbling to true. However in my main application this
EventListener never fires
systemManager.addEventListener(TweetCommEvent.RATE_LIMIT_STATUS,
onRateLimitHandler);
Any help would be greatly appreciated as i am out ideas and have exausted
google and my flex friends.
Thanks,
Sean