Search code examples
actionscript-3flashrootevent-listenerdispatchevent

ActionScript 3 - accessing variable on root not working


I have a variable (String) frame 1 scene 1 called 'test'. I also have a movieclip called 'pointerMC'. Inside pointerMC, I have another movieclip called handMC. Inside handMC, I want to dispatch an event like so:

root.dispatchEvent(new Event("eventName"));

except I want "eventName" to be the 'test' variable which holds a string, so something like this:

root.dispatchEvent(new Event(root.test));

but when I do this, it gives an error saying:

Symbol 'handMC', Layer 'actions', Frame 20, Line 2  1119: Access of possibly undefined property test through a reference with static type flash.display:DisplayObject.

Why am I getting this error?


Solution

  • Found the answer:

    root.dispatchEvent(new Event(MovieClip(root).test));
    

    worked.