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

load in external swf on click - button

New Here ,
Apr 22, 2010 Apr 22, 2010

help please

was so easy in AS2 but seem really complicated in AS3, doh!

would someone please help?? I am trying to simply load in an external swf when I click a button.

I have created a button on the stage called it 'my_button'

I can get the swf to load in automatically but I am not understanding the script for loading it in on a click.....would someone pleae explain what script I need to have : (

this is the script I have for loading automatically;

var loader_mc : Loader = new Loader();
var urlRequest : URLRequest = new URLRequest("photography.swf");
loader_mc.load(urlRequest);
addChild(loader_mc);

works great just would like to have it load in on a button click, can someone help


aaaarrrgghhhh!!!!

TOPICS
ActionScript
8.3K
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 ,
Apr 22, 2010 Apr 22, 2010

:

yourbutton.addEventListener(MouseEvent.CLICK,f);

var loader_mc : Loader = new Loader();
var urlRequest : URLRequest = new URLRequest("photography.swf");

function f(e:Event){
loader_mc.load(urlRequest);
addChild(loader_mc);

}
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 ,
Apr 22, 2010 Apr 22, 2010

HA! HA! that works great, thank you!!

I have come accross one other thing when doing it, I am going to have 5 button in total each loading in external swfs for example

button 1 - loads in photography.swf

button 2 - loads in video.swf

button 3 - loads in art.swf

button 4 - loads in music.swf

button 5 - loads in print.swf


so I did this thinking I could just duplicate, create another button, call it 'my_video' and use . .

my_button.addEventListener(MouseEvent.CLICK, buttonClick)

function buttonClick(e:MouseEvent):void
{
     var loader_mc : Loader = new Loader();
      var urlRequest : URLRequest = new URLRequest("photography.swf");
      loader_mc.load(urlRequest);
      addChild(loader_mc);
}

my_video.addEventListener(MouseEvent.CLICK, buttonClick)
function buttonClick(e:MouseEvent):void
{
     var loader_mc : Loader = new Loader();
      var urlRequest : URLRequest = new URLRequest("video.swf");
      loader_mc.load(urlRequest);
      addChild(loader_mc);
}

and so ...

....but oh! know it just goes crazy,do I need to unload the swf that is already loaded also??

whats the simplest way of doing this

thanks for your help!

thanks for your 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 ,
Apr 22, 2010 Apr 22, 2010

you can't have 2 functions with the same name.  how will flash know which you want to use?

each button listener should call a different function or, you could call one function and use a property of your buttons to indicate which swf to load.

but the simplest is to use a different function for each button.

p.s.  please mark this thread as answered, if you can.

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 ,
Apr 22, 2010 Apr 22, 2010

hi there

ok so do you mean something like this in terms of adding more functions;

button 1.)        function buttonClick(e:MouseEvent):void

button 2.)       function buttonClick2(e:MouseEvent):void

button 3.)     function buttonClick3(e:MouseEvent):void

etc

can it be done like this?

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 ,
Apr 22, 2010 Apr 22, 2010

ok, I got that working but the other swf stays there, would you beable to

help me understand what it is I need to do in order to get the previous exteranl swf to unload?

see is what I have;

my_button.addEventListener(MouseEvent.CLICK, buttonClick)

function buttonClick(e:MouseEvent):void
{
     var loader_mc : Loader = new Loader();
      var urlRequest : URLRequest = new URLRequest("photography.swf");
      loader_mc.load(urlRequest);
      addChild(loader_mc);
}


my_video.addEventListener(MouseEvent.CLICK, buttonClick2)

function buttonClick2(e:MouseEvent):void
{
     var loader_mc : Loader = new Loader();
      var urlRequest : URLRequest = new URLRequest("video.swf");
      loader_mc.load(urlRequest);
      addChild(loader_mc);
}

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 ,
Apr 22, 2010 Apr 22, 2010

is it easier to load the swf's into a level so this would mean that the previous would be replace with the new

swf loading into the same level, if so how do I incorporate the script into what I have

aaarrrrrrghhhH!!!

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 ,
Apr 22, 2010 Apr 22, 2010

in AS2 you this - ("photography.swf",2);

but how for AS3

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 ,
Apr 22, 2010 Apr 22, 2010

use one loader.  and if you're publishing for fp 10, use unloadAndStop():

var loader_mc : Loader = new  Loader();

   addChild(loader_mc);


my_button.addEventListener(MouseEvent.CLICK,  buttonClick)

function  buttonClick(e:MouseEvent):void
{
     try{

loader_mc.unloadAndStop();

} catch(e:Error) {

}
      var urlRequest : URLRequest = new  URLRequest("photography.swf");
      loader_mc.load(urlRequest);
}


my_video.addEventListener(MouseEvent.CLICK,  buttonClick2)

function  buttonClick2(e:MouseEvent):void
{

     try{

loader_mc.unloadAndStop();

} catch(e:Error) {

}

      var urlRequest : URLRequest = new  URLRequest("video.swf");
      loader_mc.load(urlRequest);
}

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 ,
Apr 22, 2010 Apr 22, 2010

p.s.  please mark this thread as answered, if you can.


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 ,
Apr 22, 2010 Apr 22, 2010

can't seem to get it working ????

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 ,
Apr 22, 2010 Apr 22, 2010

ha! ha!

fantastic, yes I got it working with that script, changed it to publish for flash player 10 as was on 9 and it work perfects.

thank you for all your help, you have been very helpfull. Yes will mark answered!

big thank you!

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 ,
Apr 22, 2010 Apr 22, 2010

you're welcome.


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 ,
Apr 26, 2010 Apr 26, 2010

Hi Klad

I was wonderinf if I could pick your brain about something related to what you helped me with. I keep coming accross sitse which are full screen flash but when you resize the browser elements of the movie stay constrained. I have been wondering for a while how this is done and have come across something called "liquifying website", see hhis post: http://forums.adobe.com/message/2677379#2677379

... but also heard that there is an application, flex, that can constrain sites??

I guess my question is how is this done and using the script you helped me with is it possible to constrain the container "loader_mc" within that script that would simply stop things being resized as and when the browser is?

thanks for any help and knowledge on this topic : )

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 ,
Apr 26, 2010 Apr 26, 2010

that's done using a stage resize event listener and customizing the positioning and sizing of display objects.

i didn't check your reference but checking liquid flash should be the correct topic.

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 ,
Apr 26, 2010 Apr 26, 2010

thanks for that!

will check liquid flash out

many thanks

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 ,
Mar 15, 2012 Mar 15, 2012

AWESOME!! I've been looking for this code, I knew it wasn't as complicated as other snippets I've been given....THAT DON'T WORK!

THANX!

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 ,
Mar 15, 2012 Mar 15, 2012
LATEST

you're welcome.

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