I´d like to get a lift on this subject too because I´m still trying to
understand the best way to generate my own events

and I found this small example below which I mainly understood but seemed
too simple compared with Eka "pro" solution ...

but I´m still stucked with the fact that I don´t find elsewhere the
EventDispatcher.initialize(this);
reference, does it come from AsBroadcaster as superclass ???

probably I put myself in a middle of something much more complex than I´m
able to follow right now .. if so, forgive me and forget about it .. I´ll
generate other post to get the proper help   -)

class TestClass
{
   var dispatchEvent:Function;
   var addEventListener:Function;
   var removeEventListener:Function;
   var mcLoader:MovieClipLoader;
   var loadListener:Object;

   function TestClass()
   {
       EventDispatcher.initialize(this);
       mcLoader = new MovieClipLoader();
       loadListener = new Object();
       mcLoader.addListener(loadListener);
   }

   function testing()
   {
       dispatchEvent({target:this, type:"testEvent", message:"Hello"});
   }

   function testingAgain()
   {
       _root.createEmptyMovieClip("myMc", _root.getNextHighestDepth());

       mcLoader.loadClip("Blue.jpg", _root.myMc);

       var thisClass:TestClass = this; //store reference to this class

       loadListener.onLoadInit = function(target_mc:MovieClip):Void
       {
           trace("Content loaded to "+target_mc);
//call on thisClass
           thisClass.dispatchEvent({target:this, type:"testEventAgain",
message:"HelloAgain"});
       }
   }
}



var myObj:TestClass = new TestClass();

myListener = {};
myListener.testEvent = function(evtObj:Object):Void
{
trace(evtObj.message);
trace("Event dispatched: " + evtObj.type);
}
myObj.addEventListener("testEvent", myListener);

myListener.testEventAgain = function(evtObj:Object):Void
{
trace(evtObj.message);
trace("Event dispatched: " + evtObj.type);
}
myObj.addEventListener("testEventAgain", myListener)

myObj.testing();
myObj.testingAgain();



2006/6/8, Sam <[EMAIL PROTECTED]>:

Hi,
Thanks, sorry I quickly stripped the classes down for posting here.

Can you explain this portion of your code:

static private var __ASPF__ = _global.ASSetPropFlags(SampleView,
["LOAD_SOMETHING"], 7, 7) ;

On Jun 8, 2006, at 2:06 PM, eka wrote:

> Hello :)
>
> your code is very light :)
>
> try this :
>
> import mx.events.EventDispatcher ;
>
> class com.test.mvc.AbstractView{
>
>    // ---o Constructor
>
>    private function AbstractView() {
>
>        // Abstract Class !!
>
>    }
>
>    // ----o Init EventDispatcher
>
>    static private var __initDispatcher = EventDispatcher.initialize(
> AbstractView.prototype) ;
>
>    public var addEventListener:Function;
>    public var removeEventListener:Function;
>    public var dispatchEvent:Function;
>
>    // ----o You Methods etc...
>
> }
>
> --------
>
> import mx.utils.Delegate ;
>
> class com.test.app.SampleView extends AbstractView{
>
>    // ----o Constructor
>
>    public function SampleView() {
>
>        // your code in the constructor
>
>    }
>
>    // ----o Constants
>
>    static public var LOAD_SOMETHING:String = "onLoadSomething" ;
>
>    static private var __ASPF__ = _global.ASSetPropFlags(SampleView,
> ["LOAD_SOMETHING"], 7, 7) ;
>
>    // ----o Public Properties
>
>    public var test_mc:MovieClip ;
>
>    // ----o Public Methods
>
>    public function load_something(t):Void {
>
>        test_mc = t.attachMovie("test_mc.jpg", "test_mc",
> t.getNextHighestDepth());
>        test_mc.onPress = Delegate.create(this, _onPress) ;
>
>        // ---o Dispatch event
>
>        var e = { type: LOAD_SOMETHING, target:this } ;
>
>        dispatchEvent( { type: LOAD_SOMETHING , target:this} ); //
> test 1
>
>    }
>
>    // ----o Private Methods
>
>    private function _onPress():Void {
>
>        var e = { type: LOAD_SOMETHING, target:test_mc } ;
>
>        dispatchEvent ( e ) ; // test 2
>
>    }
> }
>
> or show more code please ;)
>
> EKA+ :)
>
>
> 2006/6/8, Sam <[EMAIL PROTECTED]>:
>>
>> Hi,
>> Is it possible to dispatch events from a simple call to a method?
>>
>> I have a view class that extends an abstract view class that contains
>> the EventDispatcher  class.
>> I don't have a problem dispatching events from onPress and other
>> handler, but what if I want to dispatch an event when simply calling
>> a method?
>>
>>
>> class com.test.mvc.AbstractView{
>>
>>      public var addEventListener:Function;
>>         public var removeEventListener:Function;
>>         public var dispatchEvent:Function;
>> }
>>
>> class com.test.app.SampleView extends AbstractView{
>>
>>         public function load_something(t)
>>         {
>>                 test_mc = t.attachMovie("test_mc.jpg", "test_mc",
>> t.getNextHighestDepth());
>>
>>                 dispatchEvent({type:"onLoadSomething"}); //this
>> does not
>> work
>>
>>                 test_mc.onPress = function(){
>>                         this._parent._parent.dispatchEvent
>> ({type:"onLoadSomething", target:this});        //this works
>>                          }
>>
>>         }
>> }
>>
>>
>> _______________________________________________
>> [email protected]
>> 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
>>
> _______________________________________________
> [email protected]
> 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
>

_______________________________________________
[email protected]
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




--
João Carlos
_______________________________________________
[email protected]
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

Reply via email to