Loading multiple external SWF dynamically

  • soumik
  • Novice
  • Novice
  • soumik
  • Posts: 29

Post 3+ Months Ago

I am using this code to load swf movies dynamically:

_root.link is the movie number I want to target and it generates from a buttons press, for eg. the value 1.



Code: [ Select ]
stop();
url = "movie"+_root.link+".swf";
loadMovie(url, 2);

trace(url);
  1. stop();
  2. url = "movie"+_root.link+".swf";
  3. loadMovie(url, 2);
  4. trace(url);


Now, the trace value of the variable URL is becoming movie1.swf without quotes. But in order to load the movie 'movie1.swf' the value is required to be inside a quote. so the loadmovie function will be like this:

Quote:
loadMovie("Movie1.swf", 2);


but right now the first Code is rendering the URL as:
loadMovie(Movie1.swf, 2); where it is required to be like loadMovie("Movie1.swf", 2);

Can anyone please suggest how do I load external swf movies dynamically and target them from parent movie clip

AND

target the parent movie swf from the externally loaded movieclip?

Thanks
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

when something is between double quotes that means its a string ...

and your url variable will output a string which should basically work , you can test that by declaring it ...
var url:String = "movie"+_root.link+".swf";
  • soumik
  • Novice
  • Novice
  • soumik
  • Posts: 29

Post 3+ Months Ago

classified wrote:
when something is between double quotes that means its a string ...

and your url variable will output a string which should basically work , you can test that by declaring it ...
var url:String = "movie"+_root.link+".swf";


:( :( Just tried, but no hope with that... it again trace as movie1.swf not "movie1.swf"
  • soumik
  • Novice
  • Novice
  • soumik
  • Posts: 29

Post 3+ Months Ago

I jsut found in the actionscript refernce that you can get quotes (") by using a back slash before to it..

var firstStr:String = "That is \"Fine\"";

will be rendered as = That is "Fine"

So, I went with:
Code: [ Select ]
stop();
var url:String = "\"movie"+_root.link+".swf\"";
trace(loadMovie(url, 21));
  1. stop();
  2. var url:String = "\"movie"+_root.link+".swf\"";
  3. trace(loadMovie(url, 21));


But it is showign undefined....
  • dhonsvick
  • Beginner
  • Beginner
  • dhonsvick
  • Posts: 49

Post 3+ Months Ago

Here is a function I am using in a current project, I am using loadClip rather than Load movie so that I can get the progress of the loading and read it back to a progressbar. to my knowlage loadMovie will not do this. you would simply call this such as.

_root.loadMoviesPlease("test.swf","_root","http://.yaddayadda.com/");


I would put this in an actions layer at the begining of the movie



Code: [ Select ]

function loadMoviesPlease(movie,instance,my_url){
    var my_back:MovieClip = instance.createEmptyMovieClip("back_drop",-50000);
    
        var mcl:MovieClipLoader = new MovieClipLoader();
        var mclL:Object = new Object();
        
        mclL.onLoadProgress = function(target,loaded,total){
        _root.loader_mc.percent.text = Math.round((loaded / total)* 100) +"%";
        }
    mclL.onLoadInit = function(){
        _root.loader_mc._visible = false;
        _root.loader.percent.text = "";
        _root.background_image.text = "I got here";
        
        }
mcl.addListener(mclL);
_root.loader_mc._visible = true;
var my_clip = mcl.loadClip(my_url+movie, my_back);
        
}
  1. function loadMoviesPlease(movie,instance,my_url){
  2.     var my_back:MovieClip = instance.createEmptyMovieClip("back_drop",-50000);
  3.     
  4.         var mcl:MovieClipLoader = new MovieClipLoader();
  5.         var mclL:Object = new Object();
  6.         
  7.         mclL.onLoadProgress = function(target,loaded,total){
  8.         _root.loader_mc.percent.text = Math.round((loaded / total)* 100) +"%";
  9.         }
  10.     mclL.onLoadInit = function(){
  11.         _root.loader_mc._visible = false;
  12.         _root.loader.percent.text = "";
  13.         _root.background_image.text = "I got here";
  14.         
  15.         }
  16. mcl.addListener(mclL);
  17. _root.loader_mc._visible = true;
  18. var my_clip = mcl.loadClip(my_url+movie, my_back);
  19.         
  20. }


Now you notice that the first thing I do is createAn Empty Movie Clip. This is not completely nessassry, I just seem to have an easier time in AS using a movie Clip created in AS, you could point toward an existing movie Clip Such as one you have listed under the name of holder....but you need to know it's full path. To find that path simply to to the desire movie clip instance and click on it and add the following code in tha actions panel.

Code: [ Select ]
on(release){
  trace(this);
}
  1. on(release){
  2.   trace(this);
  3. }


Test movie, now click on the desire spot it will squeal like a pig and tell you its path. something like _level0.my_holder_clip. Copy that down and remove that Code from the clip. Now you can call the function like this from anywhere in your flash movie, following the dry policy (Do Not Repeat Yourself).

_root.loadMoviesPlease("test.swf",_level0.my_holder_clip, "http://.yaddayadda.com/");
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

soumik wrote:
I jsut found in the actionscript refernce that you can get quotes (") by using a back slash before to it..

var firstStr:String = "That is "Fine"";

will be rendered as = That is "Fine"

So, I went with:
Code: [ Select ]
stop();
var url:String = ""movie"+_root.link+".swf"";
trace(loadMovie(url, 21));
  1. stop();
  2. var url:String = ""movie"+_root.link+".swf"";
  3. trace(loadMovie(url, 21));


But it is showign undefined....


yeah that what i meant , a string will not be traced between quotes ...
you are actually doing it right ...

You cant trace loadmovie , trace the variable ...
trace(url);

here read carefully http://livedocs.adobe.com/flash/mx2004/ ... 01519.html
  • soumik
  • Novice
  • Novice
  • soumik
  • Posts: 29

Post 3+ Months Ago

Quote:
yeah that what i meant , a string will not be traced between quotes ...

you are actually doing it right ...


You cant trace loadmovie , trace the variable ...

trace(url);


here read carefully http://livedocs.adobe.com/flash/mx2004/ ... pl/common/ html/wwhelp.htm?context=Flash_MX_2004&file=00001519.html



It same all the way.. I just tried with:

Code: [ Select ]
_root.link = 1;
var url:String = "\"movie"+_root.link+".swf\"";

loadMovie(url, 21);
trace(url);
  1. _root.link = 1;
  2. var url:String = "\"movie"+_root.link+".swf\"";
  3. loadMovie(url, 21);
  4. trace(url);

where the traced URL value is ("movie1.swf")....with quotes.. but that doesn't bring the external movie movie1.swf to the stage.. where making the loadMovie function static brings it quite easily..

Code: [ Select ]
_root.link = 1;
var url:String = "\"movie"+_root.link+".swf\"";

loadMovie("movie1.swf", 21);
trace(url);
  1. _root.link = 1;
  2. var url:String = "\"movie"+_root.link+".swf\"";
  3. loadMovie("movie1.swf", 21);
  4. trace(url);
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

okay this should explain to you what im trying to explain :)
http://www.zainals.com/loads/loadmovie.zip

unzip content in the same file , open index.fla and look at the code , then run it . . . ...
  • soumik
  • Novice
  • Novice
  • soumik
  • Posts: 29

Post 3+ Months Ago

classified wrote:
okay this should explain to you what im trying to explain :)
http://www.zainals.com/loads/loadmovie.zip

unzip content in the same file , open index.fla and look at the code , then run it . . . ...


This is awsome! Thanks a lot..

But here is my simple question...

If the CODE 1 can bring the external swf why cant the CODE 2? I am just giving the path from the variable URL...

Code: [ Select ]
CODE 1

_root.link = 1;
//url = "movie1.swf";

loadMovie("movie1.swf", 21);
  1. CODE 1
  2. _root.link = 1;
  3. //url = "movie1.swf";
  4. loadMovie("movie1.swf", 21);


Code: [ Select ]
CODE 2

_root.link = 1;
url = "movie1.swf";

loadMovie(url, 21);
  1. CODE 2
  2. _root.link = 1;
  3. url = "movie1.swf";
  4. loadMovie(url, 21);
  • classified
  • Expert
  • Expert
  • User avatar
  • Posts: 540
  • Loc: Bahrain

Post 3+ Months Ago

hmmm im not really sure ... what is 21 anyway ? is it a level ?
http://livedocs.adobe.com/flash/8/main/ ... 01739.html

it should work fine ...
  • soumik
  • Novice
  • Novice
  • soumik
  • Posts: 29

Post 3+ Months Ago

yes thats level, suppose to be 2 for me.. seems i have mis-typed...but that wont create any problem..

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 20 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.