load in external swf on click - button
Copy link to clipboard
Copied
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!!!!
Copy link to clipboard
Copied
:
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);
}
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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!!!
Copy link to clipboard
Copied
in AS2 you this - ("photography.swf",2);
but how for AS3
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
p.s. please mark this thread as answered, if you can.
Copy link to clipboard
Copied
can't seem to get it working ????
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
you're welcome.
Copy link to clipboard
Copied
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 : )
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
thanks for that!
will check liquid flash out
many thanks
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
you're welcome.

