How to Load an external swf using loadmovie in AS3

I need to create a button with script, on rollover load an external swf into movieclip in AS3.  This was able to create this in AS2, but I need to create this in AS3

Thanks again Ned.
Kenneth Russell
graphic artist, Sr.
Lockheed Martin - MS2
2323 Eastern Blvd., Baltimore, MD 21220
Phone 410.682.0554    Fax 410.682.0543
From: Ned Murphy <[email protected]>
Reply-To: [email protected]
Date: Thu, 23 Jul 2009 19:08:25 -0600
To: kenneth russell <[email protected]>
Subject: How to Load an external swf using loadmovie in AS3
In AS3 you use the Loader class to load external swf's and image files.  You
should be able to find examples both in the Flash help files and these forums
if you search.  If you aren't aware of how to code buttons in AS3, that can be
found as well.  In AS3, just about any kind of interction involves the use of
event listeners in combination event handler functions... in the case of a
button rollover an example would be...
btnName.addEventListener(MouseEvent.ROLL_OVER, overHandler);
function overHandler(evt:MouseEvent):void {
     // your loading code or whatever
>

Similar Messages

  • Trouble loading an external swf file implemented with AS3

    I am using Adobe Flash CS3
    At first, I tried
    swf_mc.loadMovie("//swf file
    location");
    It gave me
    quote:
    Warning: 1060: Migration issue: The method loadMovie is no
    longer supported.
    USE: var l = new Loader(); addChild(l); l.load(new
    URLRequest("your url"));.
    Well, the given code isn't working at all.
    But since it is a migration error, I thought maybe I can just
    save it into Flash5 format with AS1. Then it worked with most
    external swf files. However, the one I am trying to load is a swf
    file with AS3, so my older version swf can't load it at all.
    Anyone has any ideas about how to load an external AS3 swf
    file?

    AS3 is a completely different beast than AS1 or 2. loadMovie
    was removed from the language.
    The answer to your question is two fold. First, Adobe was
    kind enough to give us the code when it finds a migration issue.
    var _ldr:Loader = new Loader();
    addChild( _ldr );
    _ldr.load( new URLRequest( "your url") );
    Handling progress has also changed. I have a ContentLoader
    package on my site that you're free to use that should familiarize
    you with the new way that things are done in AS3.
    http://sd-dezign.com/blog/?page_id=10

  • LoadMovie- loading an external swf into movieclip in AS3

    Im extremely frustrated.........im trying to do something
    that was once very simple, which has now become over complicated
    unecessecarily.....i want to do a simple loadMovie type action and
    load an external clip into a movieclip called ph. my AS2 code would
    be:
    loadMovie("ExternalMovieClip.swf","ph");
    or
    on(release) {
    loadMovie("ExternalMovieClip.swf","ph");
    This no longer works. Can somebody tell me the new code that
    i would use with AS3 to do exactly what i just demonstrated? I
    honestly dont even want to touch AS3. The only reason i want to use
    it is because it makes skinning the components SOOOOOO much easier
    than AS2. That is the one and only reason im trying to convert to
    AS3. All the new load movie AS3 examples ive seen on google look
    like half a page long to do what i used to do in 2 lines. There
    must be a simpler and much easier way. I am a designer. It looks to
    me like Adobe went back to making flash for programmers only again
    leaving us designers out of the mix. Someone please help me, im
    desperate. I also have other old code that im sure im going to have
    to convert to AS3 for it to still work, and i may eventually need
    help with that as well, but ill stick with this loadMovie problem
    for now. Any and all help is appreciated. Thanks

    have a look here:
    http://www.smithmediafusion.com/blog/?p=381
    use this:
    var i =new Loader();
    i.load(new URLRequest(”yourSwf.swf”));
    myMC.addChild(i)
    myMC is the name of your clip on the stage.
    Dan Smith > adobe community expert
    Flash Helps >
    http://www.smithmediafusion.com/blog/?cat=11
    http://www.dsmith.tv

  • How to Load/Unload external SWF

    Hey all, I'm in a desperate struggle to meet a deadline for college coursework. I am unable to UNLOAD an external SWF file that I have put inside another SWF file. The problem that is occurring is, although it loads successfully, when I attempt to navigate to another page after viewing the external SWF, I expect it to close as it goes on to another page however, it remains in place. If i then go back on to the page that it is loading from, it will start to keep adding more and more SWF's. The print screens should explain it easier... Below i'll post the code that I'm using currently. The external SWF I am trying to load/unload is an interactive hangman game (whether it being interactive has an effect I do not know), but any and all help with this would be seriously appreciated!
    The code currently being used is:
    var _swfLoader:Loader;
    var _swfContent:MovieClip;
    loadSWF("Real Hangman.swf");
    function loadSWF(path:String):void {
       var _req:URLRequest = new URLRequest();
       _req.url = path;
       _swfLoader = new Loader();
       setupListeners(_swfLoader.contentLoaderInfo);
       _swfLoader.load(_req);
    function setupListeners(dispatcher:IEventDispatcher):void {
       dispatcher.addEventListener(Event.COMPLETE, addSWF);
       dispatcher.addEventListener(ProgressEvent.PROGRESS, preloadSWF);
    function preloadSWF(event:ProgressEvent):void {
       var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;
       // swfPreloader.percentTF.text = _perc + "%";
    function addSWF(event:Event):void {
       event.target.removeEventListener(Event.COMPLETE, addSWF);
       event.target.removeEventListener(ProgressEvent.PROGRESS, preloadSWF);
       _swfContent = event.target.content;
       _swfContent.addEventListener("close", unloadSWF);
       addChild(_swfContent);
    function unloadSWF(event:Event):void {
       _swfLoader.unloadAndStop();
    removeChild(_swfContent);
       _swfContent = null;
    This printscreen is showing what it looks like in the Flash view (plain background and external SWF loads when this SWF is published)
    What it looks like when loaded as published swf
    Picture of the external SWF working inside the other SWF
    Picture of it not being able to unload when i navigate to another page!
    Finally, a picture of it doubling up when i proceed to go on the 'game' page again, it just keeps loading the SWF's rather than unloading them!

    for example, file1 consits of two buttons, and also considered as main page. As i click on these two buttons , it will lead me go to open the external file2.swf, and file3.swf respectively. (file2.swf and file3.swf could have other navigation buttons, however, i am just simplify here).
    the code you provided is working fine. but i want to totally remove/unlink the orginal file (file1.swf) when i click on either buttons which could lead me to other page (file1.swf or file2.swf).
    Besides that, in file2.swf and file3.swf could have another "back" button to turn it back to the main page (file1.swf). When the user click on that back button, the file2.swf will unloaded...and file1.swf will be called back again...
    can it  be done?
    so sorry if my poor explanation makes you confuse..
    thank you.

  • How to  affect size of movies using loadMovie CS4, as3

    I have loaded a .swf into my main timeline, but it's quite large. I am trying to get it to fit in the constraints of my current movie. I have read that by putting it into a movie clip, it will constrain to that dimension. How do I accomplish this?

    If you know what scaleX and scaleY you will need you could just add it your code. Something like this:
    loader.scaleX=loader.scaleY=50;
    But if the content you will load is of different sizes and will maybe need different scales you could use code like below.
    import flash.display.Loader;
    import flash.events.Event;
    import flash.display.MovieClip;
    import flash.net.URLRequest;
    var loader:Loader=new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handleComplete)
    loader.load(new URLRequest("banner.swf"));
    addChild(loader);
    function handleComplete(e:Event){
    var target:Loader=Loader(e.currentTarget.loader);
         trace(target.width)
    Depending upon what you need to do you could change that trace to some kind of measurement of the width and then use some arithmetic to scale the clip to a specific size.

  • FAQ: How do I load an external SWF file into a parent SWF file?

    A ton of Flash users visit Adobe’s we site every month wondering  about how to load an external SWF file from within another SWF.
    Adobe's own TechNote on the subject attempts to answer the basic question, along with some common follow-up questions, including:
    How do I load more than one SWF?
    How do I load a SWF into a specific location in the display list?
    How do I resize the loaded SWF?
    How do I set its X and Y location?
    Here are some additional resources that elaborate on loading content and on working with the display list:
    Sample files for the above TechNote. A set of 3 FLA and 3 corresponding SWF files, including a parent SWF and 2 SWFs that the parent loads.
    Help > AS3 Developer’s Guide > Loading an external SWF file
    Help > AS3 Developer’s Guide > Loading display content dynamically
    Loading multiple external SWFs within a main SWF – CreativeCow.net forums
    Video tutorial: ActionScript 101 – Episode 6: Adding named objects to the Stage. By Doug Winnie. An example of how to add the loaded external asset to the Stage and modify its location or other properties.
    Video tutorial: Preloading in ActionScript 3.0.  By Lee Brimelow. A slightly more complicated example, showing how to  make the parent SWF display information about the progress of loading  the external SWF.
    Tutorial: Loading and unloading SWFs - FlashAndMath.com
    This article provides several examples of how to communicate between a parent SWF file and the loaded SWF:
    SWF to SWF Communcation via ActionScript 3.0 (by kglad)

    quote:
    Originally posted by:
    NedWebs
    You now seem to want to get rid of the swf once it has loaded
    and played itself thru. To do that you would need to have something
    in the swf itself that triggers its removal in its last frame. The
    following might work...
    MovieClip(this.parent).removeChild(this);
    Unfortunately I couldn't get this to work. I placed it on the
    last frame of the SWF to be called - is that right?
    I am not sure I am doing it correctly...

  • Loading an external .swf then referencing to it's label

    I'm new with Actionscript and am currently working at
    building a website. I've got a lot figured out so far but one
    problem I'm running into is when I try to load an external .swf
    using the loader component and then reference it or try to point to
    it within my main .swf I can only load the "gallery.swf." through
    myLoader.contentPath = "gallery.swf";
    I'm trying to load it and then point to a specific label so
    it loads that frame or label. I've created separate labels for each
    image in my gallery so that when I point to them with AS, it knows
    which image to load. It worked when I had the gallery in the main
    .swf but when I used the loader component it didn't work.
    The AS I used that worked before I made a separate .swf and
    used a loader was:
    on(release) {
    _parent._parent._parent.photos_MC.gotoAndPlay("img1");
    what I thought would work was:
    on(release){
    _parent._parent._parent.myLoader.contentPath =
    gallery.swf.photos_MC.gotoAndPlay("img1");
    I'm probably totally off, but if anyone could help out I
    would appreciate it!

    This looks like AS2 code, you may want to post there.
    Assuming this is AS2 code, the contentPath of the Loader specifies
    the url to load. Once the swf is loaded, you can then gotoAndPlay()
    to the label you want.
    Hope that helps.

  • Loading an external SWF in and displaying it behind overlay/watermark

    I am building a SWF and the goal is to load in an external SWF file and then display that within my container. They are totally unrelated items and I do not want to modify the functionality of the item I am loading in. My SWF will briefly display a watermark overlay, but then disappear. Can anyone guide me into this best way of doing this?
    Also, is there anyway to get the properties from the SWF I loaded in (namely height and width) so I might be able to easily adjust the size of my SWF to match?
    Thanks!

    just load your external swf using the loader class.  what you described doing is standard stuff and nothing special needs to be done.
    however, you must wait until loading is complete before you can access the loaded object's width and height.

  • How can I load an external SWF into a movie clip that's inside other movie clip?

    Hi.
    I creating my first flash (actionscript 3.0) website but I'm
    stuck with a visual effect I want to create.
    I have a window on my website called contentWindow. Every
    time you click a button this window is supposed to leave the stage,
    load the requested content and return to the stage.
    The sliding window is a movie clip with 83 frames, 21 to
    enter the stage, 21 to leave the stage again, 20 for nothing (its
    just to simulate the loading time) and 21 to return to the stage.
    Now my goal is, when the user clicks on a navigation button,
    the window exits the stage, loads an external SWF with the content,
    and then returns to the stage.
    I've the "window" movie clip with an instance name of
    "contentWindow". Inside there is another movie clip with an
    instance name of "contentLoader". The content that the user
    requested should appear inside the "contentLoader".
    Now, when the contentWindow leaves the stage, I get this
    error message:
    quote:
    TypeError: Error #1009: Cannot access a property or method of
    a null object reference.
    at rwd_fla::MainTimeline/trigger()
    If I switch
    "contentWindow.contentLoader.addChild(navLoader);" for
    "contentWindow.addChild(navLoader);" it works fine, but the
    external SWF doesn't move with the window.
    How can I load an external SWF into a movie clip that's
    inside other movie clip?

    Hi,
    Recently, I have been putting together a flash presentation.
    And I am just wondering if the following might help you, in your
    communication with the said swf file:
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    onComplete);
    function onComplete(event:Event):void
    event.target.content.thinggy_mc.y -= 100;
    Not the best example, but this allows you to target a mc
    within an external swf file. I think if you look up this code, you
    will have an answer ;)
    Kind Regards,
    Boxing Boom

  • How may load an external (html) file in swf? Anyone!!!!!

    hi all,
        How may load an external html file in swf? such as google.com in a movieclip.
    anyone may help me.........????????

    With Flash, you can't do this.
    Just with FlashBuilder and Air (something like HTMLLoader  , not sure now)
    I mean loading in a movieclip..
    Of course you can open a page to display in a browser.

  • Loading external swf using Loader.load() method is delayed with flash player 10.1 and next versions.

    I am trying to load an external swf file of size 300 kb using Loader.load() method and trying to access some objects in it and i am getting some delay in loading the external file with flash players 10.1 and next versions.
    The action script code used to load:
    var strUrl:String="toLoad.swf";
    var urlReq:URLRequest=new URLRequest(strUrl);
    var ldrLoader:Loader = new Loader();
    var ldrLoaderContext:LoaderContext = new LoaderContext();
    ldrLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, externakSwfLoaded);
    ldrLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorInLoadingSwf);
    ldrLoader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorInLoadingSwf);
    ldrLoaderContext.applicationDomain = ApplicationDomain.currentDomain;
    ldrLoader.load(urlReq, ldrLoaderContext);
    addChild(ldrLoader);
    System specifications:
    O.S. Windows XP sp2 (32 bit)
    Browser IE 6.0 (128 bit)
    Flash Player version WIN 10,2,152,32

    I think you are lost. This forum is for ROME. It sounds like you want one of the Flash or Flex forums...
    Good luck!
    Harbs

  • How to load and unload external .swfs in a main .fla then load another external .swf on top

    I know that the question sounds confusing. I am new to AS3 but a little dangerous with it.
    The project
    I'm putting together a website tour with has a main .fla with navigation buttons. The navigation buttons load external .swfs using X and Y properties. Every external .swf houses a scrubber bar, play pause buttons which calls to a movie clip which houses the animation.
    The problem:
    Everything was working great, until someone mentioned "Hey, what if at the end of each loaded external .swf, a button appears that says "go to next section".
    So basically we are trying to give the user another way to get to the next section in the left hand navigation once the animation ends, in addition to being able to click in the left hand navigation for the next section. It's kind of like when a youTube video ends and it displays a button to go to the next movie that's in line, but you can also do it in the thumnail navigation as well.
    Ok, let's try it. Well, after many nights, searching the web and trying everything I am waving the white flag. I went through the lynda.com book over and over but I get an error message when I add code related to the parent timeline. I can actually get the next section to load on top of the previously loaded .swf, but it's buggy and I think the previous section is showing through underneath. Plus the scrubber isn't really working right. Since every .swf has a scrubber to control it, shouldn't it just load on top of the previous .swf? Do I need to add coding related to the parent timeline?
    I don't know if I should paste my code here, I have a sample .fla too. Help is so greatly appreciated!!!! If this can work, I think it would be very useful for anyone else doing something like this - I would definitely share any knowledge gained!
    Thanks.
    Jen

    If you want to utilize that code as a starting point (hopefully you understand what it does, and that the code actually works), then you need to modify it such that the array at the start has your filenames instead of the three it now shows, and the three buttons it uses are changed to the next and previous buttons you intend to use.  Here are the functions you need to make adjustments to...
    function onCompletePreloading():void {
            _loadedSWFs = 0;
            contentContainer.addChild(_swfClipsArr[_loadedSWFs]);
            next_btn.addEventListener(MouseEvent.CLICK, setContent);
            prev_btn.addEventListener(MouseEvent.CLICK, setContent);
    function setContent(event:MouseEvent):void {
            var _swfToAdd:MovieClip;
            if(event.currentTarget.name == "next_btn") {
                _loadedSWFs += 1;
                if(_loadedSWFs == _swfClipsArr.length){
                       _loadedSWFs = 0;
            } else if(event.currentTarget.name == "prev_btn"){
                _loadedSWFs -= 1;
                if(_loadedSWFs == -1){
                       _loadedSWFs = _swfClipsArr.length-1;
            _swfToAdd = _swfClipsArr[_loadedSWFs];
            contentContainer.removeChildAt(contentContainer.numChildren-1);
            contentContainer.addChild(_swfToAdd);
            trace(_swfToAdd.customID);

  • Loading External SWF using Absolute Path

    Hi,
    I am having trouble loading an external swf on a server using the absolute path. This external swf uses webcam streams and is loaded in the original swf file using the URL request code. I can load other swfs but just not that one. I have set the permission of the external swf to allow write/read/execute. Any help is apprieciated.
    P.S. I have also tried changing the location and name but still doesn't help.
    //Loads the augmented SWF into the main timeline.
    var request:URLRequest = new URLRequest("http://www.reminisce.me/files/jz_AR.swf");
    var loader:Loader = new Loader()
    loader.load(request);
    arHolder.addChild(loader);
    arHolder.x=300;
    arHolder.y=125;
    Thank you for your help in advance.
    -John

    I can´t get the linked swf to run in any browser, are you sure that it compiled right?

  • Need help loading an external SWF

    I'm not very proficient in Flash, so any help will be greatly appreciated. I'm trying to load an external SWF with the following code:
    T1_Bttn_BloodCar.onRelease = function() {
    t1_images_mc.loadMovie("images/T1_Gallery/BloodCar_SWF/T1_BloodCar.swf");
    t1_images_mc._alpha = 0;
    It loads the SWF, but doesn't play it correctly when I test it. Here's how the loaded movie is supposed to look:
    http://www.theroboteye.com/T1_BloodCar.html
    But instead, it plays without the transitions, like this:
    http://www.theroboteye.com/TRE2009b.html
    I've been trying to figure this out for a few days and have tried adding "this._lockroot = true;" to the SWF I'm trying to load, but I can't get it to play correctly. Can anyone tell me what I'm doing wrong? Thanks in advance.

    Try using the MovieClipLoader class (loadClip method) instead of the loadMovie method.  That way you can have a listener that waits for the movie to be loaded and then pull it into play, assigning actions and properties to it after the fact.

  • Loading an external swf and unloading the parent one

    Hi there i have made a navigation in flash and 3 buttons that load some external swf's. Problem is that when they load the parent swf keeps playing in the background. How can i make them play separately and make the navigation stage dissapear completely when they load?

    I have attempted to use the same Loader but it doesnt replace it i dont know why.
    var myLoader:Loader = new Loader();       
    var myLoaderMain:URLRequest = new URLRequest("main1.swf");
    var myLoaderQuiz:URLRequest = new URLRequest("quiz.swf");
    var myLoaderAnimation:URLRequest = new URLRequest("athens_animation.swf");
    var myLoaderVideo:URLRequest = new URLRequest("videogallery.swf");
    videogallerybtn.addEventListener(MouseEvent.CLICK, videoFunc);
    function videoFunc(curEvt:MouseEvent) {
              myLoader.load(myLoaderVideo);
              addChild(myLoader);
    Quizbtn.addEventListener(MouseEvent.CLICK, quizFunc);
    function quizFunc(curEvt:MouseEvent) {
              myLoader.load(myLoaderQuiz);
              addChild(myLoader);
    Animationbtn.addEventListener(MouseEvent.CLICK, AnimationFunc);
    function AnimationFunc(curEvt:MouseEvent) {
              myLoader.load(myLoaderAnimation);
              addChild(myLoader);

Maybe you are looking for