Copy link to clipboard
Copied
Alright. Here's the deal. I have 7 buttons on my main page, on the left side of the screen. I want the buttons to load the external swf on the right, and then unload when a different button is pressed. Do I need to make an array? Do I need an empty movie clip to load each swf into?
///////////////Buttons/////////////////////
graphic design - loads thumbnail scroll bar
mixed media - loads thumbnail scroll bar
photography - loads thumbnail scroll bar
illustration - loads thumbnail scroll bar
words - loads story list
contact - loads contact info
about - loads bio
////////////////////////////////////////////
Thanks for any help.
if you can't publish for flash player 10, you'll need to use the unload() method instead of unloadAndStop().
Copy link to clipboard
Copied
Or if anyone knows a good tutorial they can direct me towards, that would be great.
Copy link to clipboard
Copied
just use one loader:
var ldr:Loader;
function onButtonClick(e:MouseEvent){
if(ldr!=null){
ldr.unloadAndStop();
} else {
ldr=new Loader();
}
ldr.load(new URLRequest(e.currentTarget.urlS)); // assign a urlS property fo each movieclip button
}
Copy link to clipboard
Copied
Ok, thanks. Bare with me though. It's been three years since I have worked in actionscript.
Are you saying I need to make each of my "buttons" a movieclip?
And what do you mean "assign a urlS property for each movieclip button" Do you mean "contact.swf" for the contact button?
Do I place that code on each movieclip button? Or on the main timeline?
Can you give me an example in your code of what your talking about?
Copy link to clipboard
Copied
you don't need to use movieclip buttons but it's a lot easier to encode, if you do:
button1.urlS = "swfone.swf";
button2.urlS = "2ndswf.swf";
button3.urlS = "swf3.swf";
button1.addEventListener(MouseEvent.CLICK,onButtonClick);
button2.addEventListener(MouseEvent.CLICK,onButtonClick);
button3.addEventListener(MouseEvent.CLICK,onButtonClick);
var ldr:Loader;
function onButtonClick(e:MouseEvent){
if(ldr!=null){
ldr.unloadAndStop();
} else {
ldr=new Loader();
}
ldr.load(new URLRequest(e.currentTarget.urlS)); // assign a urlS property fo each movieclip button
}
Copy link to clipboard
Copied
Ok, so im testing the code in a test .fla
I am getting this compiler error message: 1061: Call to a possibly undefined method unloadAndStop through a reference with static type flash.display:Loader. ldr.unloadAndStop();
I have three movie clips on the stage:
red
black
blue
each with a corresponding instance name of Red, Black, and Blue
I have this code on a seperate layer called "actions" on the main timeline:
Red.urlS = "introIMAGE.swf";
Black.urlS = "Jill and the Wolf_closeup.jpg";
Blue.urlS = "Death of the Bear_closeup.jpg";
Red.addEventListener(MouseEvent.CLICK,onButtonClick);
Black.addEventListener(MouseEvent.CLICK,onButtonClick);
Blue.addEventListener(MouseEvent.CLICK,onButtonClick);
var ldr:Loader;
function onButtonClick(e:MouseEvent){
if(ldr!=null){
ldr.unloadAndStop();
} else {
ldr=new Loader();
}
ldr.load(new URLRequest(e.currentTarget.urlS)); // assign a urlS property fo each movieclip button
}
Copy link to clipboard
Copied
if you can't publish for flash player 10, you'll need to use the unload() method instead of unloadAndStop().
Copy link to clipboard
Copied
Alright. So, that fixed the error message. However when I test the movie and click on a button nothing loads. Does that have anything to do with how I set up my buttons\movies? Do I nest the button inside a movie? I have everything in the same folder as the .fla
Thanks so much for the help.
Copy link to clipboard
Copied
do you see any error messages
Copy link to clipboard
Copied
No error messages. Just nothing loads when I click a button.
-- Sent from my Palm Pre
On Jun 30, 2010 11:28 PM, kglad <forums@adobe.com> wrote:
do you see any error messages
Copy link to clipboard
Copied
did you add ldr to the display list?
Copy link to clipboard
Copied
I'm not sure I know what you mean by that. I have the code set up exactly as shown above. With the exception of changing the unload() so it will run in player 9.0
Copy link to clipboard
Copied
use:
var ldr:Loader;
function onButtonClick(e:MouseEvent){
if(ldr!=null){
ldr.unload();
} else {
ldr=new Loader();
addChild(ldr);
}
ldr.load(new URLRequest(e.currentTarget.urlS)); // assign a urlS property fo each movieclip button
}
Copy link to clipboard
Copied
That works! Thanks
One last question.
Where would I place the x and y coordinates in the code, so I can postion what I am loading on the stage?
Copy link to clipboard
Copied
to center:
button1.urlS = "swfone.swf";
button2.urlS = "2ndswf.swf";
button3.urlS = "swf3.swf";
button1.addEventListener(MouseEvent.CLICK,onButtonClick);
button2.addEventListener(MouseEvent.CLICK,onButtonClick);
button3.addEventListener(MouseEvent.CLICK,onButtonClick);
var ldr:Loader;
function onButtonClick(e:MouseEvent){
if(ldr!=null){
ldr.unload();
} else {
ldr=new Loader();
ldr.addEventListener(Event.COMPLETE,loadCompleteF);
addChild(ldr);
}
ldr.load(new URLRequest(e.currentTarget.urlS)); // assign a urlS property fo each movieclip button
}
function loadCompleteF(e:Event){
ldr.x=(stage.stageWidth-ldr.width)/2;
ldr.y=(stage.stageHeight-ldr.height)/2;
}
Copy link to clipboard
Copied
That did not seem to have an effect on anything.
Copy link to clipboard
Copied
copy and paste your code.
Copy link to clipboard
Copied
Red.urlS = "introIMAGE.swf";
Black.urlS = "new scroller.swf";
Blue.urlS = "Death of the Bear_closeup.jpg";
Red.addEventListener(MouseEvent.CLICK,onButtonClick);
Black.addEventListener(MouseEvent.CLICK,onButtonClick);
Blue.addEventListener(MouseEvent.CLICK,onButtonClick);
var ldr:Loader;
function onButtonClick(e:MouseEvent){
if(ldr!=null){
ldr.unload();
} else {
ldr=new Loader();
ldr.addEventListener(Event.COMPLETE,loadCompleteF);
addChild(ldr);
}
ldr.load(new URLRequest(e.currentTarget.urlS)); // assign a urlS property fo each movieclip button
}
function loadCompleteF(e:Event){
ldr.x=(stage.stageWidth-ldr.width)/2;
ldr.y=(stage.stageHeight-ldr.height)/2;
}
Copy link to clipboard
Copied
there's nothing wrong with that code. what do you see when you click on Blue that makes you think the image is not centered?
Copy link to clipboard
Copied
The image is off to the left of the screen. I have tried changing the x and y numbers and it has no effect.
Copy link to clipboard
Copied
you're either seeing something else of you have some other code that causing that problem.
start over with a new fla, add that code and your three buttons and retest.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now