kagali-san
kagali-san

Reputation: 3082

AS3: let event listener in loaded SWF catch events from parent SWF

This isn't an exact duplicate of AS3: add event listener to loaded swf, actually it seems to be a mirror situation with non-mirror solution..

I have a test flash file that registers its own listener at first frame's actions.

trace("it's going to be OK");
stage.addEventListener(KeyboardEvent.KEY_DOWN, aKey);

Unfortunately neither line works when .swf is loaded into another movie. Assuming that stage object is wrong for such situations, which object should be used to get listener?

Is it necessary to rewrite loader in parent swf, as said in the linked question?

Upvotes: 0

Views: 828

Answers (1)

user562566
user562566

Reputation:

Try this inside the SWF you're loading:

addEventListener(Event.ADDED_TO_STAGE, onAdded);

function onAdded(e:Event):void
{
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKey);
}

function onKey(e:KeyboardEvent):void
{
    trace('key down');
}

Upvotes: 1

Related Questions