Jump to content
Search Community

How can I load external SWF files in a movie clip based on button clicked?

learner_7n test
Moderator Tag

Recommended Posts

Hi,

 

How to load external SWF files in a specific movie clip based on a button clicked. Say, I have 4 SWF files like ...

1) Main.swf

2) Services.swf

3) AboutUs.swr

4) ContactUs.swf

 

And I have the buttons with same name like (Main, Services, AboutUs & ContactUs) and when I cllick on Services button the Services.swf to be loaded.... so on...

 

Actually I have several external SWF files to load in this way.

 

The following code is okay but I need to write code for each button seperately. How can I modify the code to resolve my problem?

 

 

var mySwf1:SWFLoader = new SWFLoader("Main.swf", {width:600, height:400, container:SWFContainer_mc, onComplete:completeHandler1});

mySwf1.load();

function completeHandler1(event:LoaderEvent):void {
TweenLite.to(event.target.content, 0,{alpha:0});
TweenMax.fromTo(event.target.content, 3, {x:0, y:0, width:600, height:400, alpha:.5}, {x:0, y:0, width:600, height:400, alpha:1, delay:1});
}

 

Thanks in advance for any help.

 

Regards.

Link to comment
Share on other sites

I made a very basic example showing how you can use the instance name of the button that is clicked to load the proper swf.

 

var swf:SWFLoader;
//buttons have same instance names as the swfs that will load
services.addEventListener(MouseEvent.CLICK, loadSwf);
contactus.addEventListener(MouseEvent.CLICK, loadSwf);

function loadSwf(e:MouseEvent):void{
//if there is previously loaded content then get rid of it
if(swf){
 swf.unload()
 };
swf = new SWFLoader(e.target.name + ".swf", {container:SWFContainer_mc, onComplete:completeHandler1, alpha:0});
swf.load();
}


function completeHandler1(event:LoaderEvent):void {
 TweenMax.to(event.target.content, 1, { alpha:1});
}

 

files attached

loadFromButton.zip

  • Like 1
Link to comment
Share on other sites

I made a very basic example showing how you can use the instance name of the button that is clicked to load the proper swf.

 

var swf:SWFLoader;
//buttons have same instance names as the swfs that will load
services.addEventListener(MouseEvent.CLICK, loadSwf);
contactus.addEventListener(MouseEvent.CLICK, loadSwf);

function loadSwf(e:MouseEvent):void{
//if there is previously loaded content then get rid of it
if(swf){
 swf.unload()
 };
swf = new SWFLoader(e.target.name + ".swf", {container:SWFContainer_mc, onComplete:completeHandler1, alpha:0});
swf.load();
}


function completeHandler1(event:LoaderEvent):void {
 TweenMax.to(event.target.content, 1, { alpha:1});
}

 

files attached

I made a very basic example showing how you can use the instance name of the button that is clicked to load the proper swf.

 

var swf:SWFLoader;
//buttons have same instance names as the swfs that will load
services.addEventListener(MouseEvent.CLICK, loadSwf);
contactus.addEventListener(MouseEvent.CLICK, loadSwf);

function loadSwf(e:MouseEvent):void{
//if there is previously loaded content then get rid of it
if(swf){
 swf.unload()
 };
swf = new SWFLoader(e.target.name + ".swf", {container:SWFContainer_mc, onComplete:completeHandler1, alpha:0});
swf.load();
}


function completeHandler1(event:LoaderEvent):void {
 TweenMax.to(event.target.content, 1, { alpha:1});
}

 

files attached

 

Thanks a million for your kind help.

 

Regards.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...