Jump to content


Loaded SWF accesing a method in the Main Document Class

Moderator Tag

Recommended Posts

I have an SWF with timeline animation loaded via Loadermax and I'm trying to access a method inside my Main Document Class from the 50th frame in my loaded SWF but no luck so far.


I tried putting MovieClip(parent.parent) in the 50th frame




if (parent is MovieClip) {


// downcast parent to MovieClip assinging

// it to a new variable

var par:MovieClip = MovieClip(parent); // or: parent as MovieClip;




and no luck so far.


Anybody know a way to do this. TIA



Link to comment
Share on other sites

Keep in mind that SWFLoader will load your swf into a ContentDisplay object - THAT'S the object that gets added to your parent swf's stage (or wherever you decide to put it). So the hierarchy is like:


main swf > SWFLoader's ContentDisplay Sprite > subloaded swf


(assuming you put it on the root level of the stage)


And ContentDisplay is a Sprite, not a MovieClip.


Does that clear things up for you? If you're still having trouble, feel free to post a sample set of FLA files (doesn't have to be your production files).

Link to comment
Share on other sites

Thanks Jack for the quick response!


Based in ur hierarchy, parent.parent should work, but still no luck.


Here's what I have:






public class Main extends MovieClip{


public var device:Sprite = new Sprite ;


public function Main():void{





public function init():void{

subUI = new SWFLoader("External.swf",{name:section,



x: X,

y: Y,



onProgress: subUIProgress,

onComplete: subUIComplete});



Loaded = true;

isOn = true;



public function FunctionTest():void{

trace("Function Test");








on 50th frame from the action panel, I wrote:


if (parent.parent is MovieClip) {

var par:MovieClip = MovieClip(parent.parent);





There's really no actionscript in the loaded SWF except for the last frame which I wrote above.

Link to comment
Share on other sites

Worked like a charm for me (see attached).


There must be something else funky in your file/code - looks like you're putting it in a container named "device", so you'd need to go one more level up, like parent.parent.parent. You might want to look into using a static function so that you could simply do Main.FunctionTest();

Link to comment
Share on other sites

Thanks I just got it too and about to post it here ! parent.parent.parent did it. Ur right, it is device's child.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.