A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: How to load an external movie into Flash AS2

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1

    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..

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    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

  3. #3
    Newbie Infantry infantry's Avatar
    Join Date
    Jan 2003
    Location
    Chi-Town
    Posts
    258
    Not to thread hijack...

    But how do I center the external MovieClip?
    I'm still learning Flash!

  4. #4
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    @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

  5. #5
    Newbie Infantry infantry's Avatar
    Join Date
    Jan 2003
    Location
    Chi-Town
    Posts
    258
    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!

  6. #6
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    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

  7. #7
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center