I'm not totaly sure, but you don't have to specify target - that's something that Delegate already adds to the event object it passes along
On 9/27/06, vic <[EMAIL PROTECTED]> wrote:
John, I think so but what I am trying to do it set up a BtnFunc Class that I can pass an argument to in order to set up the functionality of the button (argument bein the button instance name). I am pretty close I have this so far: FLA (with btnOnStage on stage): import mx.utils.Delegate; function handleEvent(eventObj) { trace('handleConstruct') trace(eventObj.target); trace(eventObj.type); trace(eventObj.message); trace(eventObj.time); } var myBtnClass = new BtnFunc(0, btnOnStage); myBtnClass.addEventListener('click', Delegate.create(this, handleEvent)); ---------------------- Class (BtnFunc.as): import mx.events.EventDispatcher; import mx.utils.Delegate; class BtnFunc { var addEventListener:Function; var removeEventListener:Function; var dispatchEvent:Function; function BtnFunc(id, btn) { EventDispatcher.initialize(this); btn.onRelease = function() { trace('dispatching event'); dispatchEvent({type:'click', target:this, message:btn+' was clicked'}); }; } } It is firing off the event perfectly but my listener is not getting it and thus not running the handleEvent func. What's the prob? var myClass = new Timer(1000); myClass.addEventListener('timeout', Delegate.create(this, handleConstruct)); ----- Original Message ----- From: "John Grden" <[EMAIL PROTECTED]> To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com> Sent: Wednesday, September 27, 2006 8:13 AM Subject: Re: [Flashcoders] Delegating Events and AS2 >I think Delegate gives you what you're talking about Vic - control over your > scope issues. Delegate enables you to manage scope with in your class. So, > if you have an XML object and you want to maintain the response/return in > your class, you do just as Dan has described. > > make sense? > > On 9/27/06, vic <[EMAIL PROTECTED]> wrote: >> >> Danno, that is really cool, I will try that but I have done it, I made a >> site template that, when a button is clicked it dispatches an Event...but I >> had the hardest time doing it. I am looking for a simple way to do it that >> works in a Class. without worrying about scope. Mine relies heavily upon >> scope. Anyone have any example? Thanks, V >> >> >> ---------- Original Message ---------------------------------- >> From: Dan Rogers <[EMAIL PROTECTED]> >> Reply-To: Flashcoders mailing list <flashcoders@chattyfig.figleaf.com> >> Date: Tue, 26 Sep 2006 20:55:32 -0700 >> >> >Vic, if you've ever used the XML or NetStream classes... it mimics >> >those types of event updates. For example... >> > >> >var xmlData = new XML(); >> >xmlData.onLoad = function () { >> > // gets invoked by the XML instance >> >} >> > >> >So if you delegate the onLoad method, you get something like this: >> > >> >xmlData.onLoad = Delegate.create(this, xmlDataLoad); >> > >> >... which is essentially what I am trying to do with my own classes. >> >Another reason I like delegating events this way, is that the >> >compiler will catch typos in the names of the event functions, so I >> >am not searching around trying to figure out why a certain event is >> >not firing. >> > >> >-Danro >> > >> > >> >On Sep 26, 2006, at 7:06 PM, vic wrote: >> > >> >> Hey Dan, I like the way you do it, its pretty simple. But here is, >> >> what probably will be an incredibly stupid question: >> >> >> >> How do I capture the event? Thanks, V >> >> >> >> I personally use an extremely simplified way of dealing with events. >> >> I've used EventDispatcher before, but it feels like overkill most of >> >> the time. I realize my method has no ability to multicast events, >> >> but it's quick, easy to read and gets the job done. >> >> >> >> Here's an example: >> >> >> >> ___________________________ >> >> // WidgetManager.as >> >> >> >> import mx.utils.Delegate; >> >> >> >> class WidgetManager { >> >> private var _widget1:Widget; >> >> private var _widget2:Widget; >> >> >> >> public function WidgetManager (timeline:MovieClip) { >> >> _widget1 = new Widget(1, timeline.widget1_mc); >> >> _widget1.clickEvent = Delegate.create(this, widgetClick); // add event >> >> >> >> _widget2 = new Widget(2, timeline.widget2_mc); >> >> _widget2.clickEvent = Delegate.create(this, widgetClick); // add event >> >> } >> >> >> >> private function widgetClick (eventObj:Object):Void { >> >> trace("widget " + eventObj.id + " was clicked"); >> >> eventObj.target.clickEvent = null; // remove event >> >> } >> >> } >> >> >> >> ___________________________ >> >> // Widget.as >> >> >> >> import mx.utils.Delegate; >> >> >> >> class Widget { >> >> public var clickEvent:Function; // event method >> >> private var _id:Number; >> >> private var _buttonMC:MovieClip; >> >> >> >> public function Widget (id:Number, mc:MovieClip) { >> >> _id = id; >> >> _buttonMC = mc; >> >> _buttonMC.onPress = Delegate.create(this, buttonPress); >> >> } >> >> >> >> public function buttonPress ():Void { >> >> clickEvent({target:this, id: _id}); >> >> } >> >> } >> >> >> >> >> >> >> >> >> >> On Sep 26, 2006, at 12:09 PM, Sean Scott wrote: >> >> >> >>> Hi All!, >> >>> >> >>> wondering if someone can point me in the right direction. I am >> >>> trying >> >>> to find a ASBoradcast / Event Dispatcher light model for my app. >> >>> >> >>> Basically i have a number of MCs that will have to either react to >> >>> events being broadcast or broadcast their own. >> >>> >> >>> I have Essential AS2 by Colin Moock. Trying to find something i can >> >>> import and maybe pass scope to it, vs have my main class extend it. >> >>> >> >>> I've googled, searched the archived and exausted my more talented >> >>> flash developer friends. >> >>> >> >>> Thanks, >> >>> Sean >> >>> _______________________________________________ >> >>> Flashcoders@chattyfig.figleaf.com >> >>> To change your subscription options or search the archive: >> >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >>> >> >>> Brought to you by Fig Leaf Software >> >>> Premier Authorized Adobe Consulting and Training >> >>> http://www.figleaf.com >> >>> http://training.figleaf.com >> >> >> >> _______________________________________________ >> >> Flashcoders@chattyfig.figleaf.com >> >> To change your subscription options or search the archive: >> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> >> >> Brought to you by Fig Leaf Software >> >> Premier Authorized Adobe Consulting and Training >> >> http://www.figleaf.com >> >> http://training.figleaf.com >> >> >> >> _______________________________________________ >> >> Flashcoders@chattyfig.figleaf.com >> >> To change your subscription options or search the archive: >> >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> >> >> Brought to you by Fig Leaf Software >> >> Premier Authorized Adobe Consulting and Training >> >> http://www.figleaf.com >> >> http://training.figleaf.com >> > >> >_______________________________________________ >> >Flashcoders@chattyfig.figleaf.com >> >To change your subscription options or search the archive: >> >http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> > >> >Brought to you by Fig Leaf Software >> >Premier Authorized Adobe Consulting and Training >> >http://www.figleaf.com >> >http://training.figleaf.com >> > >> >> _______________________________________________ >> Flashcoders@chattyfig.figleaf.com >> To change your subscription options or search the archive: >> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >> >> Brought to you by Fig Leaf Software >> Premier Authorized Adobe Consulting and Training >> http://www.figleaf.com >> http://training.figleaf.com >> > > > > -- > [ JPG ] > _______________________________________________ > Flashcoders@chattyfig.figleaf.com > To change your subscription options or search the archive: > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > > Brought to you by Fig Leaf Software > Premier Authorized Adobe Consulting and Training > http://www.figleaf.com > http://training.figleaf.com > _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
-- [ JPG ] _______________________________________________ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com