Your event is being dispatched before you call addeventlistener as you are 
calling myDispatchFunction() from the constructor.

Try calling myDispatchFunction() after you have called addEventListener().

As a note, the FlexEvent.CREATION_COMPLETE event is used by flex as part of the 
component lifecycle so you should probably create your own custom event (or at 
least a custom event type.

Hope this helps
Duncan


--- In [email protected], "ouaqa" <abenef...@...> wrote:
>
> I'm still pretty new to flex & actionscript coding and sometimes i run on 
> some very frustrating problems. This is one of those.
> 
> I have an as3, and I want it to dispatch a FlexEvent.creationComplete when 
> instantiation is completed.
> yet, I can't make it work. I've read a lot of tutorials and my code seems OK, 
> but obviously it's not the case.
> 
> here's the prototype I've developed to test event dispatching outside of my 
> global application :
> 
> protoEventDispatch :
> 
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="absolute" 
> creationComplete="init()">
>       <mx:Script>
>               <![CDATA[
>                       import mx.events.FlexEvent;
>                       import protoClass.MyProtoClass;
>                       
>                       public var myObject : MyProtoClass ;
>                       
>                       private function init() : void
>                       {
>                               myObject = new MyProtoClass ();
>                               
> myObject.addEventListener(FlexEvent.CREATION_COMPLETE,traceIt);
>                       }
>                       
>                       public function traceIt (AEvent : FlexEvent) : void
>                       {
>                               trace(" event received ! "); //not trigerred...
>                       }
>                       
>               
>               ]]>
>       </mx:Script>
> </mx:Application>
> 
> 
> 
> MyProtoclass.as :
> 
> package protoClass
> {
>       import flash.events.EventDispatcher;
>       
>       import mx.events.FlexEvent;
>       
>       [Event (name="creationComplete" , type="mx.events.FlexEvent")]
>       public class MyProtoClass extends EventDispatcher
>       {
>               public function MyProtoClass() 
>               {
>                       trace ("creating protoclass");
>                       myDispatchFunction();
>               }
>               
>               public function myDispatchFunction() : void
>               {
>                       dispatchEvent(new FlexEvent 
> (FlexEvent.CREATION_COMPLETE ));
>                       trace (hasEventListener(FlexEvent.CREATION_COMPLETE)); 
> //output false
>                       trace (willTrigger(FlexEvent.CREATION_COMPLETE));  
> //output false
>               }
> 
>       }
> }
> 
> 
> I'm starting to feel desperate, especially that i'm sure that it's a 
> beginner's level error. As I'm the only flexcoder in my company, There is no 
> one else I can turn to. I wish I could bother you with more mind puzzling 
> problems...
> 
> Thanks in advance
> 
> The trace
>


Reply via email to