Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Loading and unloading of external swf's using buttons

New Here ,
Jun 30, 2010 Jun 30, 2010

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.

TOPICS
ActionScript
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 30, 2010 Jun 30, 2010

if you can't publish for flash player 10, you'll need to use the unload() method instead of unloadAndStop().

Translate
New Here ,
Jun 30, 2010 Jun 30, 2010

Or if anyone knows a good tutorial they can direct me towards, that would be great.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2010 Jun 30, 2010

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 30, 2010 Jun 30, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2010 Jun 30, 2010

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 30, 2010 Jun 30, 2010

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2010 Jun 30, 2010

if you can't publish for flash player 10, you'll need to use the unload() method instead of unloadAndStop().

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 30, 2010 Jun 30, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2010 Jun 30, 2010

do you see any error messages


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 30, 2010 Jun 30, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 30, 2010 Jun 30, 2010

did you add ldr to the display list?


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2010 Jul 01, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2010 Jul 01, 2010

use:

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();

addChild(ldr);

}

ldr.load(new  URLRequest(e.currentTarget.urlS));  // assign a urlS property fo each movieclip button

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2010 Jul 01, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2010 Jul 01, 2010

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2010 Jul 01, 2010

That did not seem to have an effect on anything.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2010 Jul 01, 2010

copy and paste your code.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2010 Jul 01, 2010

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;

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2010 Jul 01, 2010

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 01, 2010 Jul 01, 2010

The image is off to the left of the screen. I have tried changing the x and y numbers and it has no effect.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 01, 2010 Jul 01, 2010
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines