-
How to load an external movie into Flash AS2
Friends,
I want to learn how to load an external movie into flash AS2. I tried to find for 1 week. But ı could not find right documents.
Simply , ı have buttons and some other swf files. I want to call them my mainpage screen.
However, ı want to have ability of determining their position.
Before this writing , ı could load, but its positions were different . it right bottom of the page .
I wait your helps..
-
Prid - Outing
Make an empty movieclip, give it an instance name of for example, mc_container, position the movieclip wherever you want, and use this code on your Frame to load the SWF:
Actionscript Code:
mc_container.loadMovie("somefile.swf");
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Newbie Infantry
Not to thread hijack...
But how do I center the external MovieClip?
I'm still learning Flash!
-
Prid - Outing
@infantry: to do that, you'll have to create a movieclip within the loading movieclip and then center it. To do so, follow the steps on my previous post to create an empty movieclip, and then use this code on your Frame:
Actionscript Code:
mc_container.createEmptyMovieClip("holder", 0);
movieClipHolder = new MovieClipLoader(); movieLoading = new Object(); movieClipHolder.loadClip("fileToLoad.swf", mc_container.holder); movieClipHolder.addListener(movieLoading);
movieLoading.onLoadInit = function(){ mc_container.holder._x = -mc_container.holder._width/2; mc_container.holder._y = -mc_container.holder._height/2; }
Instead of loadMovie, which is very limited, we instead use MovieClipLoader, which can handle listeners. In this case, we create an empty movieclip inside the empty movieclip where the SWF file is going to be loaded, and load the desired file in there using MovieClipLoader's loadClip function. Then, we create an object to hold the onLoadInit listener, which is executed when the file has been 100% loaded and its width and height information has been retrieved. We use that information to position the X and Y of the loaded clip in the center, and we do this by dividing the width and height of the loaded clip, and assign their negative equivalents to the X and Y of the empty movieclip within the empty movieclip, mc_container!
Hope this helps
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Newbie Infantry
Thanks Ill try it.
I'm working on an ad system which is going to be viewed locally so I should be okay with using loadMovie.
I'm still learning Flash!
-
Prid - Outing
oh, but if you use loadMovie, you'll have to use an onEnterFrame loop to keep checking if the width and height of the loaded movie are greater than 0, in order to obtain the loaded movie's dimensions!
I am back, guys ... and finally 18 :P
BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS
-
Senior Member
I suggest not (never) use loadMovie().. its old..
using the newer (still old as its AS2 based) movieClip Loader class is MUCH better.. and gives you MUCH more control over your content.. (like auto centering it when itloads.. no onEnterFrame to check over & over & over & over.. and then of course you need to remember to delete it when its done)..
in my footer are MANY great links.. but the clipLoader link will give you an easy example on how to use a movieClip Loader instance vs loadMovie()..
ads or whatever.. it is just best practice to use them.
Once you use them a few times.. you will never go back to using loadMovie() again.. =)
the movieClip Loader approach gives you 'call back' functions that fire/trigger automatically on certain states of your loading.
onStart
onComplete
onInit...etc..etc..
so you can just add in any code/actions into those functions and they will execute automatically.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|