Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Beginner Flash: How to embed swf file and pass variables to it inside fla project...

Posted on 2007-07-31
15
Medium Priority
?
1,250 Views
Last Modified: 2010-05-18
I have a swf file "myfile.swf" that runs great embedded inside an html file.  I pass it variables using "flahvars=" and set many of its parameters.  But I am very new to flash, and now I would like to embed this swf file inside a new fla project that I have.  How do I embed it?  How do I create an instance of it and then pass parameters to it?

 
0
Comment
Question by:frankmorrison
15 Comments
 
LVL 1

Expert Comment

by:vanpevi
ID: 19599313
You will need to use LoadMovie or LoadMovieNum. They both accept passing variables.

You have to create an empty movie clip (an empty 'container') where you want the movie to load, then load it into this container...

http://www.adobe.com/support/flash/action_scripts/actionscript_dictionary/actionscript_dictionary423.html
0
 
LVL 37

Expert Comment

by:CyanBlue
ID: 19599903
Maybe you are looking for FlashVars...

Using FlashVars to load and display text
http://www.adobe.com/livedocs/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001424.html

CyanBlue
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19600414
I would not use loadMovie or loadMovieNum...  they are very limited and typically will cause problems when someone trys to immediately work with the properties of the loaded object...


instead work with the MovieClipLoader class...  here is a link to a tutorial:

http://www.actionscript.org/resources/articles/3/1/MovieClipLoaders-Part-1/Page1.html

the tutorial is fairly straight forward, but if you have any problems, just post them here...


rp
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:frankmorrison
ID: 19601978
rascalpants,

I see the moviecliploader class, but how do I pass variables to the swf using this class
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19602106
hmmm...  I think you are confused...  or maybe I am  :)

It is my understanding that you have a swf named "myfile.swf" and you want to have your other SWF(compiled from the new FLA) load the myfile.swf into it.  Is this correct?

You cannot embed a SWF in an FLA file...  do you mean you want to import the objects from your SWF into the new FLA (project)?

a bit more info is needed.


rp
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 19602219
Here's exactly what I want to do:

I purchased this swf component found here: "http://206.132.69.5/newuploader/SimpleDownload.html

I know how to make it work inside an html page.  But, I now need it to run inside a graphical interface which is totally made in flash.  In my graphical interface, I have a button that says "Download Wizard", which goes to a particular frame in my movie.  When the users clicks on "Download Wizard", I want to be able to create the an instance of this component at run time and pass the necessary variables it needs to run.


0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19602404
okay...   I get it now...

you just need to use the MovieClipLoader class to get the SWF into your application...  

you should just be able to use the FlashVars parameter in your new main SWF to get the data into your application...

then if you use code that is similar to the below, the myFile.swf should be able to reference the data based in the main SWF.


var thisRoot:MovieClip = this;
var holderClip:MovieClip = thisRoot.createEmptyMovieClip("myClip_mc", thisRoot.getNextHighestDepths() );

var myMCL:MovieClipLoader = new MovieClipLoader();

myMCL.onLoadInit = function ( targetMC ){
        myTrace ("Movie clip:" + targetMC + " is now initialized");
        // put code here to do something...
}

myMCL.loadClip("myfile.swf", holderClip);



rp
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19602415
the only problem I see is if the myfile.swf is using references to _global or _root or something like that...  you might have a scope problem then, but hopefully not.


rp
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19602432
BTW...

when you use FlashVars the variables that are passed can be referenced in the root timeline like this...

_root.theVariableName

or sometimes _parent.theVariableName if you need the scope to be in a movieclip...


rp
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 19602443
rascalpants: I get this error:
"There is no property with the name 'onLoadInit'."

Here's what I have on layer1:Frame1:

var thisRoot:MovieClip = this;
var holderClip:MovieClip = thisRoot.createEmptyMovieClip("myClip_mc", thisRoot.getNextHighestDepths() );

var myMCL:MovieClipLoader = new MovieClipLoader();

myMCL.onLoadInit = function ( targetMC ){
        myTrace ("Movie clip:" + targetMC + " is now initialized");
        // put code here to do something...
}

myMCL.loadClip("ElementITMultiPowUpload1.7.swf", holderClip);
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 19602502
Rascalpants:

I am still not clear how to pass variables to the swf.  One of the variables is "downloadMode".  This is what I did with no success:


var downloadMode = "Yes";

var thisRoot:MovieClip = this;
var holderClip:MovieClip = thisRoot.createEmptyMovieClip("myClip_mc", thisRoot.getNextHighestDepths() );

var myMCL:MovieClipLoader = new MovieClipLoader();

myMCL.loadClip("ElementITMultiPowUpload1.7.swf", holderClip);
0
 
LVL 22

Accepted Solution

by:
rascalpants earned 2000 total points
ID: 19602943
whoops...  forgot the listener...

var thisRoot:MovieClip = this;
var holderClip:MovieClip = thisRoot.createEmptyMovieClip("myClip_mc", thisRoot.getNextHighestDepths() );

var myMCL:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();

myListener.onLoadInit = function ( targetMC ){
        myTrace ("Movie clip:" + targetMC + " is now initialized");
        // put code here to do something...
}

myMCL.addListener( myListener );
myMCL.loadClip("ElementITMultiPowUpload1.7.swf", holderClip);


also, you pass the downloadMode in with the FlashVars just like you did when you were working with the myfile.swf alone.


if you still do not get the variables to work, then you might need to do something like this:


myListener.onLoadInit = function ( targetMC ){
        myTrace ("Movie clip:" + targetMC + " is now initialized");
        targetMC.downloadMode = "Yes";
}



rp
0
 
LVL 1

Author Comment

by:frankmorrison
ID: 19604268
rascalpants:

This works!!!! Thank you.  One last question: How do I unload the movie when in my graphical interface they go to another section of my movie.
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19604309
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 19604335
but as it is stated lower in the comments on the above link(and below), to destroy the movieclip itself, you should use removeMovieClip()

=========================

MovieClip.unloadMovie() unloads visual elements of a MovieClip that were rendered using the drawing api or by loadMovie().

MovieClip.removeMovieClip() destroys ALL properties of a MovieClip and the destroys the MovieClip itself, but only if it was created dynamically by attachMovie() or createEmptyMovieClip().

MovieClipLoader.unloadClip() performs the same action as MovieClip.unloadMovie().

MovieClipLoader.unloadClip() was intended to replace MovieClip.unloadMovie().

You would call MovieClipLoader.unloadClip() instead of MovieClip.removeMovieClip() if you want to reuse your MovieClip rather than recreate it. You may want to reuse it if properties were set on it that you want to keep, like _x and _y.

-Philip Keiter, Sphyrras

===========================



rp
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses
Course of the Month12 days, 9 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question