Target specific frame in child swf

I need to load several external swf's into a main swf beased on whatever button a user selects on the main swf. This is working just fine.

Some external swfs have subsections, like chapters in a book, that are frame labels. I want to create a "submenu" on the main file that loads the external swf, but goes to a specific frame on that swf. I just can't get it working.

The code with my main button function and loader is below.
stop();
 
var Xpos:Number=10.9;
var Ypos:Number=120;
var swf:MovieClip;
var loader:Loader=new Loader();
 
var defaultSWF:URLRequest = new URLRequest("swfs/introduction.swf");
 
loader.load(defaultSWF);
loader.x=Xpos;
loader.y=Ypos;
addChild(loader); 
function btnClick(event:MouseEvent):void {
removeChild(loader);
var newSWFRequest:URLRequest=new URLRequest("swfs/" + event.target.name + ".swf"); 
//load the loader:
loader.load(newSWFRequest);
loader.x=Xpos;
loader.y=Ypos;
addChild(loader);
}
 
//Main Btn listeners:
letter.addEventListener(MouseEvent.CLICK, btnClick);
who.addEventListener(MouseEvent.CLICK, btnClick);
what.addEventListener(MouseEvent.CLICK, btnClick);
audiences.addEventListener(MouseEvent.CLICK, btnClick);
community.addEventListener(MouseEvent.CLICK, btnClick);
//financials.addEventListener(MouseEvent.CLICK, btnClick);

Open in new window

neachtainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rascalpantsCommented:

I don't see any place in your code that does something like...  gotoAndPlay("FrameLabel");

it looks like you need to put an event listener on your Loader, and then tell that loader to go to the frame label you want...

now, I was not able to test my code, cause I don't have a prototype setup for your project, so let me know if you get any errors, and we can resolve them...


rp / ZA

stop();
 
var Xpos:Number=10.9;
var Ypos:Number=120;
var swf:MovieClip;
 
var labelArray:Array = new Array();
labelArray["introduction"] = "frame1";
labelArray["letter"] = "frame7";
labelArray["who"] = "whoFrame9";
labelArray["what"] = "frame1";
labelArray["audiences"] = "start";
labelArray["community"] = "frame8";
 
 
var theLoader:Loader=new Loader();
 
var defaultSWF:URLRequest = new URLRequest("swfs/introduction.swf");
 
theLoader.load(defaultSWF);
theLoader.addEventListener( Event.INIT, on_Init );
 
function btnClick(event:MouseEvent):void
{
	removeChild(theLoader);
	var newSWFRequest:URLRequest=new URLRequest("swfs/" + event.target.name + ".swf"); 
	//load the loader:
	
	//might need to create a new loader, and assign the event listener here to on_Init	
	
	theLoader.load(newSWFRequest);
	
}
 
 
function on_Init( evt:Event ):void
{
	var theLabel:String = labelArray[ evt.target.name ];
	swfLoaded( theLabel );
}
 
function swfLoaded( theLabel:String = null ):void
{
	theLoader.x = Xpos;
	theLoader.y = Ypos;
	addChild(theLoader);
	theLoader.gotoAndPlay( theLabel );
}
 
//Main Btn listeners:
letter.addEventListener(MouseEvent.CLICK, btnClick);
who.addEventListener(MouseEvent.CLICK, btnClick);
what.addEventListener(MouseEvent.CLICK, btnClick);
audiences.addEventListener(MouseEvent.CLICK, btnClick);
community.addEventListener(MouseEvent.CLICK, btnClick);
//financials.addEventListener(MouseEvent.CLICK, btnClick);
 
		

Open in new window

0
neachtainAuthor Commented:
OK, Rascalpants. Thanks.
The reason there's no ..gotoAndPlay.. is that I couldn't get that to work.
Before I try this, I have a question, please.
-Since I have sort of a universal button function that targets the name of the swf to be loaded based on the instance name of my button, does that mean that essentially all I have to do is load every button and where it needs to go into the array that you set up?
Thank you!
0
rascalpantsCommented:

the array I setup is an associative array, so I just used the instance name of the button as the parameter that can be used to access the frame label...

so the button letter uses...   labelArray["letter"] = "frame7";  which would go to and play a frame with the label of "frame7"

so basically, you can use the instance name in the array...  


rp / ZA


0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

neachtainAuthor Commented:
OK. So the error I got is below:

////////////////
1061: Call to a possibly undefined method gotoAndPlay through a reference with static type flash.display:Loader.

theLoader.gotoAndPlay(theLabel)
////////////////////
Any suggestions for correcting this?

Thanks!
stop();
 
var Xpos:Number=10.9;
var Ypos:Number=120;
var swf:MovieClip;
var loader:Loader=new Loader();
 
var labelArray:Array = new Array();
//labelArray["introduction"] = "1";
//labelArray["letter"] = "frame7";
//labelArray["who"] = "whoFrame9";
//labelArray["what"] = "frame1";
//labelArray["audiences"] = "start";
//labelArray["community"] = "frame8";
labelArray["communityHospitals"] = "5";
labelArray["communitySupport"] = "support";
 
 
 
var theLoader:Loader=new Loader();
 
var defaultSWF:URLRequest = new URLRequest("swfs/introduction.swf");
 
theLoader.load(defaultSWF);
theLoader.addEventListener( Event.INIT, on_Init );
 
function btnClick(event:MouseEvent):void
{
	removeChild(theLoader);
	var newSWFRequest:URLRequest=new URLRequest("swfs/" + event.target.name + ".swf"); 
	//load the loader:
	
	//might need to create a new loader, and assign the event listener here to on_Init	
	
	theLoader.load(newSWFRequest);
	
}
 
 
function on_Init( evt:Event ):void
{
	var theLabel:String = labelArray[ evt.target.name ];
	swfLoaded(theLabel);
}
 
function swfLoaded(theLabel:String = null):void
{
	theLoader.x = Xpos;
	theLoader.y = Ypos;
	addChild(theLoader);
	theLoader.gotoAndPlay(theLabel);
}
 
//Main Btn listeners:
letter.addEventListener(MouseEvent.CLICK, btnClick);
who.addEventListener(MouseEvent.CLICK, btnClick);
what.addEventListener(MouseEvent.CLICK, btnClick);
audiences.addEventListener(MouseEvent.CLICK, btnClick);
community.addEventListener(MouseEvent.CLICK, btnClick);
//financials.addEventListener(MouseEvent.CLICK, btnClick);
communityHospitals.addEventListener(MouseEvent.CLICK, btnClick);
communitySupport.addEventListener(MouseEvent.CLICK, btnClick);

Open in new window

0
rascalpantsCommented:

try changing...

theLoader.gotoAndPlay(theLabel);

to this...

var clip:MovieClip = theLoader as MovieClip;
clip.gotoAndPlay(theLabel);


rp / ZA

0
neachtainAuthor Commented:
I replaced the code and it makes sense, but I am getting another output error:

ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
      at flash.display::DisplayObjectContainer/removeChild()
      at ar6_invisibleLoaderArray_fla::MainTimeline/btnClick()

This happens with every button, and the default swf doesn't load. And again, I am too inexperienced to work out where I've gone wrong.
Thanks for any help!
0
rascalpantsCommented:

remove this line of code:

removeChild(theLoader);

I was thinking earlier that by removing the loader that we would have problems if we did not create a new one...  but I don't believe there is any need to remove it


rp / ZA
0
neachtainAuthor Commented:
OK - I tried removing removeChild(theLoader), but that didn't work. I moved a couple of things to the btnClick function, which heloed - now the swfs load on button click. However, the defaultSWF doesn't load on startup, and the swf's still don't load at the right frame. They all just load from the beginning.

Getting closer!
stop();
var Xpos:Number=10.9;
var Ypos:Number=120;
var swf:MovieClip;
var loader:Loader=new Loader();
 
var labelArray:Array = new Array();
//labelArray["introduction"] = "1";
//labelArray["letter"] = "frame7";
//labelArray["who"] = "whoFrame9";
//labelArray["what"] = "frame1";
//labelArray["audiences"] = "start";
//labelArray["community"] = "frame8";
labelArray["communityHospitals"] = "hospitals";
labelArray["communitySupport"] = "support";
 
 
 
var theLoader:Loader=new Loader();
 
var defaultSWF:URLRequest = new URLRequest("swfs/introduction.swf");
 
theLoader.load(defaultSWF);
theLoader.addEventListener( Event.INIT, on_Init );
 
 
function btnClick(event:MouseEvent):void
{
	//removeChild(theLoader);
	var newSWFRequest:URLRequest=new URLRequest("swfs/" + event.target.name + ".swf"); 
	
	theLoader.load(newSWFRequest);
	theLoader.x = Xpos;
	theLoader.y = Ypos;
	addChild(theLoader);
}
 
function on_Init( evt:Event ):void
{
	var theLabel:String = labelArray[ evt.target.name ];
	swfLoaded(theLabel);
}
 
function swfLoaded(theLabel:String = null):void
{
	removeChild(theLoader);
	var clip:MovieClip = theLoader as MovieClip;
	clip.gotoAndPlay(theLabel);
}
 
//Main Btn listeners:
letter.addEventListener(MouseEvent.CLICK, btnClick);
who.addEventListener(MouseEvent.CLICK, btnClick);
what.addEventListener(MouseEvent.CLICK, btnClick);
audiences.addEventListener(MouseEvent.CLICK, btnClick);
community.addEventListener(MouseEvent.CLICK, btnClick);
//financials.addEventListener(MouseEvent.CLICK, btnClick);
communityHospitals.addEventListener(MouseEvent.CLICK, btnClick);
communitySupport.addEventListener(MouseEvent.CLICK, btnClick);
 

Open in new window

0
rascalpantsCommented:
why are you trying to remove something?  that code is not needed, because you are still using the loader...

when you try to remove something, you can't use the code again.... and this is why your code keeps breaking...

      removeChild(theLoader);
      var clip:MovieClip = theLoader as MovieClip;
      clip.gotoAndPlay(theLabel);

this code can't work, because you have just removed theLoader... so you can't use something that just got deleted...


try getting what i gave you to work first, before you start adding in new buttons and functionality.


rp / ZA
0
neachtainAuthor Commented:
Thanks.
What I posted above is working except for the external clips loading to a specific frame, and the default swf doesn't load at all.

As I said in my previous comment, I did try to get your latest suggestion to work first. It did not work.
I have removed removeChild (again) and it still isn't working.

I've added nothing additional since several posts ago (added 2 event listeners). What I did was move the addChild to the btnClick, which actally made the swf's load.

I appreciate it if you can give me guidance on the default swf loading, and on how to make some of the swf's load at a particular frame.
Thanks

0
rascalpantsCommented:

whoops...  addChild was supposed to go in the on_init() event listener...  but yeah, you can put it in the button click code as well, because it just tells the application to add the loader to the stage when it is completely loaded...


below is the updated code...  forgot to position the default SWF and add it to the display list.  see if that works.  


FYI... i would recommend not loading your assets and placing them at float points... like 10.9  Flash doesn't really like that, and migth skew the images.


rp / ZA

// AS 3.0
 
stop();
 
var Xpos:Number=10.9;
var Ypos:Number=120;
var swf:MovieClip;
var loader:Loader = new Loader();
 
var labelArray:Array = new Array();
labelArray["introduction"] = "1";
labelArray["letter"] = "frame7";
labelArray["who"] = "whoFrame9";
labelArray["what"] = "frame1";
labelArray["audiences"] = "start";
labelArray["community"] = "frame8";
labelArray["communityHospitals"] = "hospitals";
labelArray["communitySupport"] = "support";
 
 
 
var theLoader:Loader=new Loader();
theLoader.addEventListener( Event.INIT, on_Init );
 
var defaultSWF:URLRequest = new URLRequest("swfs/introduction.swf");
 
theLoader.load( defaultSWF );
theLoader.x = Xpos;
theLoader.y = Ypos;
addChild(theLoader);
		
function btnClick(event:MouseEvent):void
{
        var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf"); 
        
        theLoader.load(newSWFRequest);
        theLoader.x = Xpos;
        theLoader.y = Ypos;
        addChild(theLoader);
}
 
function on_Init( evt:Event ):void
{
        var theLabel:String = labelArray[ evt.target.name ];
        swfLoaded(theLabel);
}
 
function swfLoaded(theLabel:String = null):void
{
        var clip:MovieClip = theLoader as MovieClip;
        clip.gotoAndPlay(theLabel);
}
 
//Main Btn listeners:
 
letter.addEventListener(MouseEvent.CLICK, btnClick);
who.addEventListener(MouseEvent.CLICK, btnClick);
what.addEventListener(MouseEvent.CLICK, btnClick);
audiences.addEventListener(MouseEvent.CLICK, btnClick);
community.addEventListener(MouseEvent.CLICK, btnClick);
//financials.addEventListener(MouseEvent.CLICK, btnClick);
communityHospitals.addEventListener(MouseEvent.CLICK, btnClick);
communitySupport.addEventListener(MouseEvent.CLICK, btnClick);
 
 

Open in new window

0
rascalpantsCommented:
BTW...  the values passed to the associative array are the names of the frame labels...

so you need to change the values that are being set for the frame labels in the below...


labelArray["introduction"] = "1";
labelArray["letter"] = "frame7";
labelArray["who"] = "whoFrame9";
labelArray["what"] = "frame1";
labelArray["audiences"] = "start";
labelArray["community"] = "frame8";
labelArray["communityHospitals"] = "hospitals";
labelArray["communitySupport"] = "support";



rp / Zone Advisor
0
neachtainAuthor Commented:
Thanks very much. I will try all of this out once I'm back at my desk. Do you have any alternate suggestions for positioning the loaded swf's? I just thought x/y/ values were pretty much my only option to get everything loaded in the right spot on stage...
0
rascalpantsCommented:
no, x,y positioning is really all you have...   but you can scale, adjust the alpha and tint... all sorts of other options...


rp / ZA
0
neachtainAuthor Commented:
Thanks, RP. Everything loads, (used your code verbatim this time), and I changed my frame labels as necessary, but none of the swf's lod to the specific requested frame.
0
rascalpantsCommented:
can you post all of your code, so I can see what you are currently working with...


rp / ZA
0
neachtainAuthor Commented:
Here's the code. The only buttons I've been testing so far ar communityHospitals thru frameTest.
Default loads fine, all other movies that shouls load at a specific frame only load from the first frame.
Thanks for your help!
stop();
 
var Xpos:Number=10.9;
var Ypos:Number=120;
var swf:MovieClip;
var loader:Loader = new Loader();
 
var labelArray:Array = new Array();
labelArray["introduction"] = "1";
labelArray["letter"] = "frame7";
labelArray["who"] = "whoFrame9";
labelArray["what"] = "frame1";
labelArray["audiences"] = "sampleFrame";
labelArray["audienceSample"] = "sampleFrame";
labelArray["community"] = "frame8";
labelArray["communityHospitals"] = "hospitals";
labelArray["communitySupport"] = "5";
labelArray["frameTest"] = "sampleFrame";
 
 
 
var theLoader:Loader=new Loader();
theLoader.addEventListener( Event.INIT, on_Init );
 
var defaultSWF:URLRequest = new URLRequest("swfs/introduction.swf");
 
theLoader.load( defaultSWF );
theLoader.x = Xpos;
theLoader.y = Ypos;
addChild(theLoader);
		
function btnClick(event:MouseEvent):void
{
        var newSWFRequest:URLRequest = new URLRequest("swfs/" + event.target.name + ".swf"); 
        
        theLoader.load(newSWFRequest);
        theLoader.x = Xpos;
        theLoader.y = Ypos;
        addChild(theLoader);
}
 
function on_Init( evt:Event ):void
{
        var theLabel:String = labelArray[ evt.target.name ];
        swfLoaded(theLabel);
}
 
function swfLoaded(theLabel:String = null):void
{
        var clip:MovieClip = theLoader as MovieClip;
        clip.gotoAndPlay(theLabel);
}
 
//Main Btn listeners:
 
//letter.addEventListener(MouseEvent.CLICK, btnClick);
//who.addEventListener(MouseEvent.CLICK, btnClick);
//what.addEventListener(MouseEvent.CLICK, btnClick);
//audiences.addEventListener(MouseEvent.CLICK, btnClick);
//community.addEventListener(MouseEvent.CLICK, btnClick);
//financials.addEventListener(MouseEvent.CLICK, btnClick);
communityHospitals.addEventListener(MouseEvent.CLICK, btnClick);
communitySupport.addEventListener(MouseEvent.CLICK, btnClick);
audienceSample.addEventListener(MouseEvent.CLICK, btnClick);
frameTest.addEventListener(MouseEvent.CLICK, btnClick);
 
////////////////////////////////////////////////

Open in new window

0
rascalpantsCommented:

okay... I make my own project example... and I changed up the code a bit...  hope you can see what I did and make it work with yours...

remove any ".txt" extentions on the files



rp / ZA
 
frameTest.zip.txt
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
neachtainAuthor Commented:
Thanks, RP. I think this will work. I really appreciate the help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.