views:

792

answers:

2

I have this code that works from an .as file

if (loaderInfo.loader)
 loaderInfo.loader.dispatchEvent(new Event("pageFinish", true));

Then I put the above code into an .fla file (another existing Flash file), but (loaderInfo.loader) always returns false, eventhough it is loaded from another swf. Hence the event is never dispatched.

Edit: I'll try explaining it a bit more.

This works:
container.swf --(loads)--> page1.swf (page1.fla + page1.as)
page1.swf does send the event to container.swf

This does not work:
container.swf --(loads)--> page2.swf (page2.fla)
page2.swf does send the event because loaderInfo.loader returns false here

There is no changes to container.swf between both cases, only changed an xml file to point to either page1.swf or page2.swf

A: 

loaderInfo is used if the swf is loaded via a Loader object. If that compiled fla swf is loaded via a Loader then loaderInfo.loader will not return false

Thanks Bjorn. But the "container" that loads both swf files is the same one. I added more details to the question :)
+1  A: 

Haven't been able to test this but just from the top of mind:

Make sure the loaded swf has got the rights to access the loader (LoaderContext, ApplicationDomain, etc.).

You can test this by writing this within your loaded clip:

trace(loaderInfo.childAllowsParent);
trace(loaderInfo.ParentAllowsChild);
trace(loaderInfo.sameDomain);

If one of those traces returns false, let us know...

Make sure your document has been fully constructed when you try to access its loader.

loaderInfo.addEventListener(Event.INIT, eventComplete);
loaderInfo.addEventListener(Event.COMPLETE, eventComplete);

function eventComplete(event:Event):void
{
    trace(event.target.loader);
}
Theo.T
Thanks Theo. Sorry I am pretty new with Flash, I don't really understand your comments. But I've added more details to the question to make it clearer. Thanks :)
Sure. Just try to add the code above on the main timeline of the clip you are loading (page2.fla) ... or in the constructor of its document class.
Theo.T
Theo, all three of them returned undefined, the same as when you run it on its own. The event dispatch (and those trace) is called after the movie has finished playing so I doubt it hasn't been fully constructed?
Btw, where is the main timeline? There are several frames that contains code, but I don't think there is any constructor... Thanks Theo
By "Main Timeline" I mean the first frame of the most top-level timeline (not a child MovieClip).
Theo.T
Sorry missed last comment regarding the "undefined", what happens if you actually write "trace(loaderInfo);" ??
Theo.T
Just did a basic test and it worked fine ! (placed the loaderInfo.loader on the first frame of the stage as explained above)
Theo.T
Hi Theo, I put the trace code to the first frame on "actions" row, which is the first row, but they are still undefined. loaderInfo only is also undefined. It's weird isn't it?
you're not exporting in AS2 or something : ) ? Must be something simple like exporting the file with another name etc. As I told you in the comment above, it worked straight forward for me. I don't think you can get more help but some good luck!
Theo.T
Hey you're right page2.fla is actually using ActionScript 2. So how do you dispatch an event from page2.fla to the loader which is AS3? Thanks Theo
ha, there you go... I don't think you can dispatch an AS2 Event to an AS3 context unfortunately. Switching one over to AS3 or rolling the other back to AS2 would be less tedious and more logic than playing with that!
Theo.T
BTW, if you really insist, you have to check out the LocalConnection class.
Theo.T
Alright at least now we know what the problem is. Thanks a lot Theo!
You can load an AVM1 (AS1 and AS2) in AVM2 (AS3) but I believe you can only play it, not access its data.
Brian Hodge
Wow LocalConnection works! That's really great Theo, thanks!