If you are using this exact code then I believe you have an error in the
constructor :

"public function MyClass"  should be  "public function MyMainClass"

also you should either set your vars as private or whatever kind you need.

Another thing, your eventlistener should have an object as second param, not
a function so your Class should become :


import myClass;
import myOtherClass;
import mx.events.EventDispatcher;

class MyMainClass
{
        private var _myClass:MyClass;
        private var _myOtherClass:MyOtherClass;
        
        public function MyMainClass() 
        {
                doStuff();
        }

        private function doStuff()
        {
                _myClass = new MyClass();
                // Refer to the listening object, in this case it's the
current Class MyMainClass (this)
                _myClass.addEventListener("onTransition", this)
                _myOtherClass = new MyOtherClass();
        }
        
        // I usually define event handlers as simple function not public nor
private - took that approach from ARP :)
        function onTransition(evtObj:Object)
        {
                trace("Hello World, the event fired");
                trace(_myOtherClass);
        }

} 

This is not tested but I believe it should yield something 

As for your MovieClip problem, I feel your pain ... seen it before and can't
remember how I fixed it. Is there a stop() at the beginning of that clip ?
in another timeline code or class ? This usually brings problems with
gotoAndPlay ... Sometimes we forget to remove a stop() at certain places
where it is unneeded - OnEnterFrame, setInterval, etc ..

HTH 

Alain

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Merrill,
Jason
Sent: 6 juin 2007 16:30
To: flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] EventDispatcher weirdness in AS2

Driving me mad.  I don't get what could possibly be happening here.  Why
would _myOtherClass instance no longer exist after the event in an
unrelated class fires?   Any ideas?

import myClass;
import myOtherClass;
import mx.events.EventDispatcher;

class MyMainClass
{

  var _myClass:MyCLass;
  var _myOtherClass:MyOtherClass;

  public function MyClass()
  {
        doStuff()
  }
  
  private function doStuff()
  {
        _myClass = new MyClass();
        _myClass.addEventListener("onTransition", onTransitionHandler);
        _myOtherClass = new MyOtherClass(); 
        trace(_myClass)         //traces [object Object] as expected
        trace(_myOtherClass)    //traces [object Object] as expected
  }

  private function onTransitionHandler():Void
  {
        //Event is heard just fine, the following traces just fine:
        trace("Hello World, the event fired!") 
        
        //but this does not:
        trace(_myOtherClass)    //traces undefined !?!
  }

}

Also, in other movie clip, a simple gotoAndPlay("theframelabel") does not
work.  It goes to the right framelabel, but willl NOTplay - even if I force
it with a mc.nextframe() and mc.play() it only advances one frame and stops
again.  There are no other stop() actions in the clip or anywhere else
referencing the clip.  Makes me wonder if my project is somehow corrupt. ?

Jason Merrill
Bank of America
GT&O Learning & Leadership Development
eTools & Multimedia Team

_______________________________________________
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

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.472 / Virus Database: 269.8.9/834 - Release Date: 2007-06-05
14:38
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.472 / Virus Database: 269.8.11/837 - Release Date: 2007-06-06
14:03
 

_______________________________________________
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

Reply via email to