AS3 external swf close self

Hello

After looking through the forums online and video tutorials...

I am always facing errors of loading an external swf into my main swf (full step width).

In my main.swf... i have several scenes.

On one of these scenes, I have an external SWF that loads my main.swf step size.

Which works very well...

BUT

I now want to close the external swf on a button (in my external swf) and to return to one of my scenes in my hand. SWF

I read many forums that talk about dispatchEvent

I tried these methods and I am still facing errors.

I want just one button on my external.swf that is farm/unloads/deletes itself... so that the user can continue by HAND. SWF after that they played OUTSIDE. SWF.

in actionscript 2, it was a breeze.

in as3, it's a useless pain in my rectum

Sorry if I've missed a lot

any help would be appreciated

jayquery

Try to change the code of loader main file for more like the following (blue nine):

var defaultSWF:URLRequest = new URLRequest ("gametestG.swf");

var loader: Loader = new Loader();
loader.contentLoaderInfo.addEventListener (Event.COMPLETE, loaderCompleteHandler);
Loader.Load (defaultSWF);

function loaderCompleteHandler(evt:Event):void {}
MovieClip (evt.target.content) .addEventListener ("closeChild", onChildClose);
addChild (loader);
}

function onChildClose(event:Event):void {}
loader.unloadAndStop ();
removeChild (loader);
}

Tags: Adobe Animate

Similar Questions

  • AS3: How to access and control embedded sounds in an external swf?

    I rarely use the sounds in AS3/Flash. I use Flash Pro CS6, but I can't seem to understand how access control (play, stop, etc) sounds embedded in a SWF external loading in the main SWF file.

    It is easy to control them when they are incorporated on the main swf. However, on a responsible external SWR, I get all sorts of errors. For this application, I really need to incorporate in the external SWF file.

    I've read several solutions, but none seems not to work.

    I integrate the sound file mp3 called soundSegment1.mp3 tool to import Flash CS6 and then open the properties panel actionscript Flash select the name of the class: SoundSegment1. Can I change the class ID and create a file named SoundSegment1.as, and it saved right next to my document class main.as in the same directory. The code for the SoundSegment1 class looks like this:

    package  {

       
    import flash.media.*;


       
    public class SoundSegment1 extends Sound
       
    {

           
    public function SoundSegment1 ()
           
    {
               
    // no code in here
           
    }


           
    public function playSound()
           
    {
               
    var soundSegment1:Sound = new SoundSegment1();
               
    var channel:SoundChannel = soundSegment1.play();
           
    }
       
    }
    }

    Then, in my main.as, I made several attempts to play this sound such as:

    var fileLocation:URLRequest = new URLRequest(SWFToLoad);

    loader.load(fileLocation);

    loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressListener);

    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeListener);

    loader.contentLoaderInfo.addEventListener(Event.INIT, initListener); 


    function initListener(e:Event):void // I also placed this code on the completeListener and it didn't work

    {

         loader.content.soundSegment1.playSound(); // doesn't work. 

    }

    I get:

    Line XXX 1061: Call to a possibly undefined method playSound through a reference with static type flash.display:DisplayObject.

    Otherwise, I also read that I should be able to do something like this anywhere in the Main.as file:

    var theClass:Class = Class(loader.content.getDefinitionByName("SoundSegment1")); var theSound:theClass = new theClass(); theSound.play()  //doesn't work either.

    I also tried on the completeListener:

    var TheClass:Class = e.target.applicationDomain.getDefinition("SoundSegment1") as Class;

    var theSound:TheClass = new TheClass();
    theSound
    .play()  //doesn't work either.

    I get:

    ReferenceError: Error #1065: Variable SoundSegment1 is not defined. at flash.system::ApplicationDomain/getDefinition()

    I'm stuck and I really need this to work. I would really appreciate your help.

    Thanks in advance for any help provided. I really need to make it work, because I can not simply incorporate into the main SWF or load them individually outside one by one.

    Thanks again!


    You can use the load and loadCompleteF below:

    var SWFToLoad: String =...;

    var s:String = "SoundSegment1";

    Load (SWFToLoad, s);

    function load (urlS:String, classS:String) {}

    var ldr:Loader = new Loader();

    ldr.contentLoaderInfo.addEventListener (Event.COMPLETE, function(e:Event){loadCompleteF(e,classS);});)

    LDR. Load (new URLRequest (URL));

    }

    function loadCompleteF(e:Event,classS:String):void {}

    var loadedAppDomain:ApplicationDomain = e.target.content.loaderInfo.applicationDomain;

    var C: Class = loadedAppDomain.getDefinition (classS) in class;

    var instance: * = new C();

    Sound (instance). Play();

    }

  • Loading external SWF in as3 SWF Loader style?

    Hello

    I recently did the replacement of as2 as3 and am still struggling to get my head to a particular aspect. I managed to load an external swf into an empty file via the script

    Import LoadDisplayObject;

    var loader: LoadDisplayObject = new LoadDisplayObject ("button_01.swf", true);

    1. loader.addEventListener ("displayObjectLoaded", onComplete, false, 0, true);

    addChild (loader);

    function onComplete(evt:Event):void {}

    trace ("received full load");

    loader.scaleX = loader.scaleY is. 75;

    }

    ... but I'm struggling with the script to make a SWF to load into a space when one of my 3 buttons is activated...

    My page currently has three buttons (button_01, button_02 and button_03) and in a local folder three separate sovereign wealth funds with the same names that I want to load, when you press the appropriate button.

    I managed to get them to load using a tutorial... but what they charge on top of each course... far from ideal. Research on the internet I found a range of different script... goal, that I can't find anywhere that I can find the script to make it work... so why I turned here.

    Any help much appreciated... Thanks in advance.

    Simply call butt1Click (null);

  • external .swf DURATION link AS3 png

    Flash allows you to compress the .png files as Photoshop can compress .jpg files better than any other tool high hand.

    I have the 77 .png files 1.8 .megs on my c: drive after I imported the and adjustment of the compression of files under the ' file > publication settings "to 75% for jpg and published the .swf with all the .png on the stage of the file size is 350 k which is 20% of the size of the original PNG file downloaded files with 77 separate application.

    I can create links in the shared .swf and test the animation with the code in the .swf shared to add holders of movieclip for each .png to the scene, but when I load the .swf shared in the main .swf Flash acts like he can't create the classes based on the link I have setup or there is no linkage of MovieClip.

    I tried a test to have the .swf shared with the png and movieclips bound to add to the assets of their own stadium and it works very well, but this means that a lot of my code and logic is included in the shared .swf that designers need to add png to. It's unfortunate AS3 sucks but I'm about done with the project if I knew that a battle AS3 would be I would have stayed with AS2 my next project will be AS2 no matter not at all. In any case I have set identifier 'class' link for each .png with a support of movieclip for each image. The 20% of the size for PNG and a single application against 77 separate application it's worth the extra effort to import the images, creating a movieclip with linkage holder but the main .swf which loads the .swf that is shared with all assets and links may not see or create assets as the shared .swf can when I test.

    We have the main .swf GET a handful of related assets .png and place them in the main .swf to load assets in different parts of the main .swf. It's cute that the shared .swf can add its own stadium-related assets but not too helpful. Also the way we deploy we can't roll a new version/Release to update the png but we can download a new .swf on the Active Server, so the png should be in a separate .swf. I can get the MovieClip shared add assets related to its own stadium during the test and when my problem loading is the main .swf which loads the shared .swf cannot create instances of the classes that are exported for the duration of sharing using binding.

    If possible I would like to know how the hell you get a handle on assets linked in a responsible external .swf. Preferably without creating my own crazy prototyped mega libraries of .as files consisting of outer class. Just a way of holding png MovieClips that have a connection and is configured for sharing the length of reference. It shouldn't really be that hard it's a simple task in AS2. I'm not a coding contest or some wild class to do the job that I want a few lines of code to create an instance of a class, then the reference to the Assembly/MovieClip holding the .png to addChild in a clip target.

    I solved it that I'm loading 77 assets incorporated into an external .swf that compresses the 77 PNG images without losing quality, it works very well.

  • External SWF dynamic text box.  How to target the area of text in AS3?

    Hello... I am loading an external file in a master file. Load the external file into an empty clip that is located on the stage of the main file. This external file that is loaded has a dynamic text box that I am trying to target using AS3.


    The way he did in AS2 has emptyMovieClipName.textBoxName.text = "whatever" "


    I tried to focus my text box using this same code, but it does not work in AS3 environment.

    Clues how proceed in AS3 would be appreciated!

    Thank you...
    Brenda

    you load not in a vacuum. you are attaching a child magazine empty and property content loader is the main timeline of your external swf.

    Here's how you need to reference your textfield in your external swf file:

  • AS3: using external swf buttons

    Hello

    I'm doing a Web site in Adobe Flash that imports an external swf file s navigation buttons.

    The problem is how my FLA file main know that the navigation buttons users urged, because the buttons and eventListeners are in the external swf file.

    With the other Word: can I make my external swf file returns a number to my website FLA file, to determine which button was pressed? If so, how?

    Here are the different has your two sovereigns can communicate:

    http://kb2.Adobe.com/community/publishing/918/cpsid_91887.html

  • Unloading of an external SWF that is loaded with a close button on the external SWF to unload

    I found a discussion on this topic, but I still have problems to work and was hoping to get some help here.

    Here, I have a file: http://www.dril-quip.com/test/main.swf

    I: main.swf (menu) and I module.swf (content)

    If you go to the wellhead systems/SS-15 BigBore II submarine and click on I have to load an external swf which covers most of the parent company.

    So far so good. My problem drains the loaded swf to 'Child' with the button provided on the loaded swf to 'Child'.

    Here is the code that I used to upload the file but I can't, for the life of me, find a way to unload.

    var bigboreLoader:Loader = new Loader();
    btnbb2.addEventListener (MouseEvent.MOUSE_UP, bigborecontent);

    function bigborecontent(event:MouseEvent):void {}
    var bigboreRequest:URLRequest = new URLRequest ("moduletemplate.swf");

    bigboreLoader.load (bigboreRequest);
    stage.addChild (bigboreLoader);

    I am sure that it requires the child to communicate with the parent somehow, but I'm at a loss. If I could get a bit of advice or a link to something to deal with this, it would be a great help. I just need to have my links loading my modules and remove it when the narrow buttong is struck on the loaded swf file. I promise you that I did some research and I confess that I found asnwers, but still they do not work. I found the code below:

    Main FLA:

    function removeF() {}

    removeChild (bigboreLoader);

    }

    var bigboreLoader:Loader = new Loader();
    btnbb2.addEventListener (MouseEvent.MOUSE_UP, bigborecontent);

    function bigborecontent(event:MouseEvent):void {}
    var bigboreRequest:URLRequest = new URLRequest ("moduletemplate.swf");

    bigboreLoader.load (bigboreRequest);
    stage.addChild (bigboreLoader);

    EXTERNAL FLA:

    btnClose2.addEventListener (MouseEvent.CLICK, bigborecontent);

    function bigborecontent(myevent:MouseEvent):void {}

    MovieClip (parent.parent) .removeF ();

    }

    I think I have a poor understanding of the code. Thanks for any help you might be able to provide.

    again, this code should all be on the same timeline as btnbb2. in main.fla.

    var bigboreLoader:Loader = new Loader();
    btnbb2.addEventListener (MouseEvent.MOUSE_UP, bigborecontent);


    function bigborecontent(event:MouseEvent):void {}
    var bigboreRequest:URLRequest = new URLRequest ("moduletemplate.swf");
    bigboreLoader.load (bigboreRequest);
    addChild (bigboreLoader);

    }

    function removeF() {}

    removeChild (bigboreLoader);

    }

    /////////////////////// end main.fla code ///////////////////////////////////////

    This code should all be on the main timeline in FLA EXTERNAL.

    and btnClose2 should be placed on the main timeline in your external fla. //

    btnClose2.addEventListener (MouseEvent.CLICK, bigborecontent);

    function bigborecontent(myevent:MouseEvent):void {}

    MovieClip (parent.parent) .removeF ();

    }

    end external fla code.

  • With the help of a button to load and unload the external SWF in AS3?

    How can I use a button to load and unload a sequence of external SWF files, as a Next button and previous?

    I don't know if it will work because apparently you are trying to load a swf AS1/2, but try

    change the line to be...

    _swfTempClip = MovieClip (event.target.content);

    If this does not work, then you will need to create _swfTempClip as a new MovieClip and add the event.target.content to this MovieClip using addChild().

  • External SWF only times, first pictures a few loops then

    Help!  I worked on this for the past few weeks.  Having read what I read.  Have tried everything I have has been published.  And still I can't get a simple external swf to load and read using AS3.  I tried several ways with the same results each time.  Here are some of the scripts I have tried.  What I would like to have happen is have a main script where I load sequentially external SWF files - there is no interaction required - this is a presentation that includes video and other SWF Flash files that I created.  Now, I just want that they all in a single flash file.  I had no problem with AS2 do this, but I do not know have agrees with AS3!  Please HELP - my date deadline is this week and I'm not even close to being ready.  Thank you!

    var myLoader:Loader = new Loader();

    var url: URLRequest = new URLRequest ("script1_3.swf");

    addChild (myLoader);

    **********************************************************************

    begin var: MovieClip;

    var beginLoader:Loader = new Loader();

    beginLoader.contentLoaderInfo.addEventListener (Event.INIT, beginLoading);

    beginLoader.load (new URLRequest ("start1_3.swf"));

    function beginLoading(evt:Event):void {}

    thisMovieClip = MovieClip (beginLoader.content);

    stage.addChild (thisMovieClip);

    thisMovieClip.play ();

    //}

    //**********************************************************

    import flash.display. *;

    import flash.net.URLRequest;

    import flash.events.Event;

    var _swfLoader1:Loader;

    var _swfContent1:MovieClip;

    loadSWF1 ("script1_3.swf");

    Play();

    function loadSWF1(path:String):void {}

    var _req1:URLRequest = new URLRequest();

    _req1. URL = path;

    _swfLoader1 = new Loader();

    setupListeners1 (_swfLoader1.contentLoaderInfo);

    _swfLoader1.load (_req1);

    //}

    function setupListeners1(dispatcher1:IEventDispatcher):void {}

    dispatcher1.addEventListener (Event.COMPLETE, addSWF1);

    dispatcher1.addEventListener (ProgressEvent.PROGRESS, preloadSWF1);

    //}

    function preloadSWF1(event:ProgressEvent):void {}

    var _perc:int = (event.bytesLoaded / event.bytesTotal) * 100;

    swfPreloader1.percentTF.text = _perc + '% ';

    //}

    function addSWF1(event:Event):void {}

    event.target.removeEventListener (Event.COMPLETE, addSWF1);

    event.target.removeEventListener (ProgressEvent.PROGRESS, preloadSWF1);

    _swfContent1 = event.target.content;

    _swfContent1.addEventListener ("close", unloadSWF1);

    addChild (_swfContent1);

    //}

    function unloadSWF1(event:Event):void {}

    _swfLoader1.unloadAndStop ();

    removeChild (_swfContent1);

    _swfContent1 = null;

    //}

    Best wishes

    Deborah

    If you do not have a stop() command in frame 50, try putting an it, or explain why you will not.  Certainly put a trace in the frame of 50 to see if you keep coming back, as in... trace ("under 50");

  • Load external swf file

    Hi all

    I am trying to load an external SWF file in my site... but it does not work. Here is my code

    public var CD:Loader = new Loader();

    protected function application1_creationCompleteHandler(event:FlexEvent):void

    {

    CD.load (new URLRequest ("http://localhost/assets/slide.swf"));

    addChild (this. (CD);

    CD.x = 2;

    CD.y = 170;

    / / TODO self-generated stub method

    }

    Can someone tell me what goes wrong...

    The url is correct and his works in my browser when I type " " http://localhost/assets/slide.swf ' in the browser... So the problem is with flex...

    I tried to load this swf into my project and it crashed the browser.  What is written this swf?  AS3 or earlier?  If I'm not mistaken load one previous VERSION other than 3 will cause additional problems and needs to work to spare but I'm not 100% sure.

  • Loading external Swf

    Hi all! I am new to the forum here and relatively new to AS3. I use FlashBuilder code. I'm trying to load a local external .swf into my application. My URLRequest happens not to be able to find the location of the local swf file. I dropped it around with my application, but no matter what I put for the url it does not find the swf file. For example, my swf is game.swf name, but no matter where I put it in the folder of the project and any combination of URL, I can't seem to access. Oddly enough, if it's in the bin-debug and I put URLRequest ("game.swf"), he will find that in the bin-debug, it seems. Please help and thanks in advance!

    In a Flash Builder project you should put it in the folder/src. The bin-debug is generated automatically with whatever you put in / SRC.

    Ideally, you should make a folder under/SRC (so/src/assets) liabilities and then load again URLRequest('assets/game.swf'); Flash Builder copy file /src liabilities more to/bin-debug and your final export file as well.

  • External SWF responsible for bringing forward

    Hello

    I am currently implementing to create a Web site using the approach platform scrolling game side. As the player/actor (a character who moves according to keyboard events) must always be at the top layer, I have difficulties to get my swf loaded on top of the drive. I am currently using Flash (as3) cs6.

    Basically, in my big scene, there are 3 layers. 1 for actionscript, the HAS a player and finally for the background.

    Player of layer contains mc and mc background player.

    Background MC contains layers of visual and collisions.

    Everything that has to do with visual, I have to put in the Visual Layer.

    In the Visual Layer, I have backgroundcontainer mc

    Then, I put the button in the mc backgroundcontainer to call the external swf, loading external swf file appears in the container.

    (I use loading/unloading of the snippet of code to call the external swf file)

    I want the external swf to appear at the top of the drive.

    ------------------------------------------------------------------------------------------ ---

    for (var fl_ChildIndex_2:int = 0;

    fl_ChildIndex_2 < this.numChildren;

    fl_ChildIndex_2 ++)

    {

    this.getChildAt (fl_ChildIndex_2) .addEventListener (MouseEvent.CLICK, fl_ClickToBringToFront_2);

    }

    function fl_ClickToBringToFront_2(event:MouseEvent):void

    {

    this.addChild (event.currentTarget as DisplayObject);

    }

    ------------------------------------------------------------------------------------------ ---

    Any help would be greatly appreciated

    If you want an object to move at the top of all the others, you can use addChild (thatobject), where thatobject corresponds to the element you want to move to the top of what anyone else.  I do not know what tent objects to affect your loop, but it seems to be changing the index of all of the child objects, rather than a single one.

  • Load external swf and stopping on the 1st frame.

    Hello everyone

    I use following code to display an external swf file on the iPad.

    var request: URLRequest = new URLRequest ("http://< server ip > / test.swf");

    loader = new Loader();

    Loader.Load (request);

    The file load passes through each image and closes the application.

    Y at - it will be a way to stop the 1st frame once the file is loaded and move between the ribs to the?

    Thank you

    If you listen to when the charger is finished, you can stop the swf file:

    var mc:MovieClip;

    loader.contentLoaderInfo.addEventListener (Event.COMPLETE, swfloaded);

    function swfloaded(e:Event) {}

    MC = e.target.content as MovieClip;

    MC. Stop();

    }

    Now you can do what you like in this clip. As:

    mc.gotoAndStop ('some ' label');

    or:

    mc.gotoAndStop (10);

  • How we prevent external swf click do not affect the parent swf

    I use the loadMovie command to load an external swf (a short course of education) in the parent swf file. The parent swf file is an interactive exercise with several buttons to answer. The user can click a button to open and close the turorial on top of the exercise.

    If the user clicks at random on the tutorial, they can accidentally click the answer buttons in the swf below parent and hear signals correct and incorrect. When they close the tutorial, they see that the answers have been given and it has a score when they have not intentionally give all the answers.

    How to prevent clicks on the external register on the parent SWF swf? Thanks in advance for any help on this matter.

    Add a rectangle step in the lowest layer of your external swf and make sure that the size of the stage of the loaded swf file and load is the same.  convert this shape to a movieclip and assign an instance name (for example, bg_mc).  in Control Panel, you can use:

    bg_mc._alpha = 0;

    {bg_mc.onRelease = Function ()}

    }

    bg_mc.useHandCursor = false;

  • load kids &gt; parents &gt; child (external SWF)

    in as3, I have a main swf file and that contains a placeholder movieclip, I want to load a swf file into this placeholder (which is not a problem), but I want to use a button in the swf file to load a new swf in the current placeholder on the main swf clip. (and unload/Park the original loaded swf).
    I tried to use parent.parent and I also read that you can use a dispatcher/listener of events in the main movie of _root, however, I don't want to recode the each film main time I add a new button in the film responsible for targeting the same clip of placeholder, but load a swf again.

    Ideas of thought would be appreciated, the solution is probably to the front, but I've searched and searched, but does not.

    Keith

    This is the code that I proposed (but now, using your reference names):

    ///////////////

    sgWeb2_btn.addEventListener (MouseEvent.CLICK, coreTwo);

    function coreTwo(e:Event):void {}

    Charger (this.parent) .load (new URLRequest ("SGCORE1.swf"));

    }

    /////////////////

    and that the code should be on the main timeline of the external swf file.

Maybe you are looking for