Child .swf problem

Hello I was hoping someone may be able to help me with a problem I have been having and unloading external .swfs, Ill try to explain this as best I can.
I have two .swf files, both of which are connected to an external .as file. One is the main, the other is the child being loaded into the main .swf file. The user clicks a button in the main .swf firing off a function contained in the .as file which loads the child .swf.
Now I have a boolean variable in the child .swf, that gets set to true at a certain part of the movie, this variable is then sent to the .as file, and caught firing off a function via ENTER_FRAME to unload the movie(unloadAndStop()). The problem I think I am having is the sprite container(which is being created in the .as file), is not being recognized as a child, thus will not unload. However if I create a CLICK  MouseEvent, and aim it towards the sprite the unloadAndStop() function works fine, but would like to avoid this if possible. This is what I have in the .as file:
(endFind is the boolean value being set in the child .swf, and the loadSWF() is being called by a button in the main .swf)
import flash.events.Event;
var url:String = "objectSearch.swf";
var _Req:URLRequest = new URLRequest(url);
var _swfLoader:Loader = new Loader();
var _swfContent:Sprite = new Sprite();
var endFind:Boolean;
function loadSWF():void {
_swfLoader.load(_Req);
_swfContent.addChild(_swfLoader);
addChild(_swfContent);
setupListeners(_swfLoader.contentLoaderInfo);
function setupListeners(dispatcher:IEventDispatcher):void {
   dispatcher.addEventListener(Event.COMPLETE, addSWF);
function addSWF(event:Event):void {
   event.target.removeEventListener(Event.COMPLETE, addSWF);
   _swfContent = event.target.content;
function unloadSWF():void {
   _swfLoader.unloadAndStop();
   trace("unloadSWF: ",_swfLoader.unloadAndStop());
//!!!!!!removeChild is throwing ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.//!!!!!!
//removeChild(_swfContent);
   //_swfContent = null;
//Adding a mouseEvent to the sprite seems to work ok
_swfContent.addEventListener(MouseEvent.CLICK,endCheck);
function endCheck(e:MouseEvent){
trace("click");
unloadSWF();
//This does not because of the unloadAndStop() method.
//addEventListener(Event.ENTER_FRAME,endCheck);
/*function endCheck(e:Event){
if(endFind==true){
  unloadSWF();
if you need any more clarification please let me know. I greatly appreciate everybodys help and feedback.

A better way to manage children is to just listen for them to tell you something and then take an action.  What that means is essentially having the child just dispatch an event and have the parent listening for it so that it can take action.  So to do that you need to assign a listener to the object after it has loaded....
function addSWF(event:Event):void {
   event.target.removeEventListener(Event.COMPLETE, addSWF);
   _swfContent = event.target.content;
  MovieClip(_swfContent).addEventListener("unloadMe", unloadSWF)
and adjust the unloading function to be the event handler....
function unloadSWF(evt:Event):void {
      ...etc
and in the child swf just have it dispatch the event your listener is waiting for when it needs to be unloaded....
dispatchEvent(new Event("unloadMe"));

Similar Messages

  • Problems accessing child swf from parent class

    First off: Hi. I'm new - to the forum and to Flash.
    I'm currently writing a flash app that requests a XML feed
    from a Java controller and loads child swfs into various parts of
    the stage based on the settings/URL details received from the XML
    feed.
    Its nearly there and I've got my head round a couple of weird
    things, but theres one thing left that I've found impossible to
    solve. Once the loader class has loaded the swf, it can't access
    its methods or set its variables and the child can't access the
    parent either (or access the parent's variables full stop). From
    what I've read this should be possible. Heres some of my code plus
    pseudo code:
    Note the Panel class is not linked to a symbol and uses
    composition to act like a movie clip, rather than inheritance.
    quote:
    class Panel{
    function Panel(owner:MovieClip, insName:String,
    depth:Number){
    initiates properties etc....
    panelMovie = owner.createEmptyMovieClip(insName,depth);
    listener.onLoadComplete = mx.utils.Delegate.create(this,
    scheduleModule);
    loader.addListener(listener);
    loader.loadClip(moduleX.url, panelMovie);
    function scheduleModule(){
    trace(panelMovie.key);
    trace(panelMove.keyTest());
    panelMovie.key = "dave";
    trace(panelMovie.key);
    Child swf:
    quote:
    var key:String = "test";
    As you can see I create an empty movieclip which I store a
    reference to in this class under the field "panelMovie". I then use
    this (instead of target_mc like you might do with an event handler)
    to try to access the child swf. The output is:
    trace(panelMovie.key); = "test" (Works fine)
    trace(panelMove.keyTest()); = (Nothing returned)
    panelMovie.key = "dave";
    trace(panelMovie.key); = "test" (Previous line = no effect)
    Is this something related to using a class? Really would be
    preferentially to keep all code outside of the fla.
    I've also tried a lot of different combinations of _root,
    _parent and _levelx. None of which I truly understand.
    Any help would be much appreciated! Plus any good tutorial
    links on timeline and referring to objects in it!
    (Couldn't find the code tag/button...)

    >>trace(panelMove.keyTest()); = (Nothing returned)
    You have panelMove here instead of panelMovie
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Parent swf call function in Child swf not working

    Hi all,
    I'm having a problem with this and I just can't figure it out
    :( (I've been trying different things and staring at it for hours
    and I'm losing my mind...)
    So I have a Parent swf that loads a Child swf (this goes
    without any problems), but I want the Parent to call a function in
    the child, now this is where it goes wrong...
    The function the Parent has to call is named "lookupcar" and
    needs to give the value "wagen" with it. The problem I think is
    that the Parent wants to call the function but it still needs to
    load (correct me if I'm wrong). Is there a way to check if the
    Child swf is loaded completely before trying to call the function?
    Could you give me an example of this please? Or any other
    suggestions on what goes wrong?
    Code in the Parent
    root.inhoud.createEmptyMovieClip("thetext", "thetext",
    this.getNextHighestDepth());
    root.inhoud.thetext.loadMovie("uitrusting-wagenpark.swf");
    root.inhoud.thetext.lookupcar(wagen);
    Code in the Child
    (the function lookupcar)
    _global.lookupcar = function(carnr:String){
    trace("LOOKUPCAR, with car nr: " + carnr);
    Thanks in advance for all the help.

    Perfect....just to make sure i m taking care of it in a nice practical way....here is how i learned to access a file located in Child (researching other posts)
    is this the way you recommend it?
    (LoaderName.content as MovieClip).functionName(new Event("whatever"))
    and in Child File we have
    function functionName(e:Event)
    i have seen other ways of calling a function in Child Swf , like using EmbedSWF and etc. wanna make sure which one is a better practice. Thanks

  • Child.swf to pass two variables to parent in global function

    Hi, I have a parent.swf and wish to load a varying child.swf as a sub-menu. How do I establish a global function that will allow the child.swf to pass back two variables (storyName & storyType) to the parent and kick off a task.
    The submenu (swf) items will change so I cannot explicitly add a listener to a child.button. The submenu is on a children’s library so will have numerous graphics and movieclips included so I don’t think it would be suitable to simply call xml data to build a menu at runtime (at my level of knowledge). There will be a number of child.swf depending on books available.
    I am not familiar with package { and public class { etc...
    In as2 I would have used a _global.function() and used that to pass the variables back to the parent and then start a parent.action.
    Totally new to AS3, suggestions appreciated. I have no problem loading the child.swf.

    Hi Ned, thank you for your response. I don’t know if it is relevant, but the container clip is run via AIR. That seems to affect some things as I’ve lost fullscreen functionality somewhere.
    I tried you suggestions, if I have translated it into place correctly I don’t know. Do I need to treat the parent.parent as a variable (yes this one is done via a loader) ?
    I get an error if I leave the function call open, I can tell I’m getting into the call as the trace on each side is happening.
    In the External Movie:
    blob_b.addEventListener(MouseEvent.CLICK, ms_bF);
    function MbRemEL(nameof:String):void {
                blob_b.removeEventListener(MouseEvent.CLICK, ms_bF);
    function ms_bF(event:MouseEvent):void {
                var m_ar:Array = new Array();
                m_ar=event.target.name.split("_");
                MbRemEL("r");
                trace("StoryMenu: "+event.target.name);
                if (this.parent.parent != null){
                            MovieClip(parent.parent).story = event.target.name;
                            //MovieClip(parent.parent).gcr(event.target.name);
                             // = TypeError: Error #1006: gcr is not a function.
                            MovieClip(parent.parent).gotoAndStop("g_home");                   
    In Container Movie:
    function gcr(stry:String):void{
                trace("gcr: "+stry);

  • Loading child SWFs with TLF content (from Flash CS5.5) generates reference errors in FB4.6

    I am currently producing e-learning content with our custom AS3-Framework.
    We normally create content files in Flash CS5.5 with dynamic text fields, which are set at runtime from our Framework (AS3 framework in FB4.6).
    Now we are in the progress of language versioning, and since one of the languages is Arabic we are changing the dynamic text fields to TLF fields.
    Then all my problems started.
    In Flash I have chosen to include the TLF engine and to export in frame 2.
    (see to: http://helpx.adobe.com/flash/kb/loading-child-swfs-tlf-content.html )
    I get this error:
    VerifyError: Error #1053: Illegal override of getEventMirror in flashx.textLayout.elements.FlowLeafElement.
                at flash.display::MovieClip/gotoAndPlay()
    I guess it is because our framework wants to gotoAndPlay before the TLF engine has been loaded.
    Can this be it?
    Any good suggestions on how to handle loading child SWFs with TLF content.

    Please refere to the following articles .. you may find some help.
    http://www.stevensacks.net/2010/05/28/flash-cs5-tlf-engine-causes-errors-with-loaded-swfs/
    http://www.adobe.com/devnet/flash/articles/preloading-tlf-rsl.html
    I also faced similar problem and posted a question at the following link, but, I still couldn't find the solution.
    http://forums.adobe.com/message/4367968#4367968

  • Using loaded fonts in child swf

    Hello,
    I have an ad container that loads a handful of resources of which some are fonts and some are swfs. My problem is that the font is loaded from an url, is registered and works fine embedding it to the textfields created in the ad container. The problem is that when I try to embed it to the textfields in some of those loaded SWFs it does not work.
    The font loads and gets registered before the swf gets loaded. The SWF file then gets an event telling it to embed the font there as well. While checking, from within the child SWF file, the Font.enumerateFonts() array I can see that the fonts have been succesfully registered. My problem is that even if that array shows me the fonts, when I try to embed them in the child SWF file nothing appears. I even use something like myTextFied.font = Fonts.enumerateFonts()[0].fontName, while embedFonts is set to true and antiliasing is set to advanced.
    I tried it in all manner of ways and none gives me any results. The font which is loaded is stored as a library item with Linkage inside a SWF file. So to load a font I load SWF file containing that font. It works fine for the ad container (main SWF) but not for children SWFs.
    Any suggestions?
    Thank you a lot!
    Vlad

    You may need to create instance of font class and register font in every loaded swf. This is an RSL approach.
    This post outlines the idea:
    http://krasimirtsonev.com/blog/article/AS3-flash-runtime-font-loading-embedding

  • Child .swf controlling parent timeline

    Hello Captivate Heroes,
    I've searched around, and can't seem to find any solid info on an issue my team is having. I'm a bit of a noob when it comes to Javascript, so I apologize if this question is too basic for this forum.
    Is it possible for an embedded .swf (created in Captivate) to control the main timeline in a parent .swf? Consider the example below:
    1) This window is an embedded .swf (another captivate file, which I’ll refer to as the “child”) that has an interactive walkthrough. It loads and begins playing immediately. I want users to complete this module and all interactions in it before continuing to the next slide in the “parent” file. Essentially, I want either the child or the parent timeline to play, but never both at the same time.
    2) This is our normal continue button, and I don’t want it appearing until 1 has been completed.
    My solution was to add a javascript call on the first slide of the child file that tells the parent file to pause its timeline (something like _root.rdcmdPause=1;). Then, do the opposite on the last child slide ( _root.rdcmdResume=1;). In this way, the parent slide would essentially pause on its first frame (which doesn’t have an active continue button) while the child animation continues to play. However, this isn’t working. It’s been a really long time since I’ve scripted, so I’m very rusty. Is that the proper way to manipulate parent variables in a child file? Do you have any other ideas on how to accomplish this task?
    I have a backup solution -- providing a "password" at the end of the child animation, which users can use to unlock the continue button. I'd rather use a more graceful solution
    Thank you in advance,
    Jamie

    Hi Jamie,
    I don't think JavaScript is going to help you here.  You need to be doing this in ActionScript 3. 
    For the non-scripting part, you can control the Captivate movie using system variables.  To pause the main slide, you could assign rdcmdPause=1 on the Slide Entry action.  You may want to adjust the slide transition to none so that it won't look faded out when it pauses the movie.  You can also show/hide items on the slide using the timeline, but it sounds like you won't really know when the Learner will be done with the interactive child .swf. 
    From what you described, it sounds like the Child .swf (#1) needs to communicate with other objects on the slide... mainly the continue button (#2).  In order to do that you'll most likely need to make the child .swf #1 into a widget so that it can communicate with the main movie and other objects on the slide.  I would suggest 3 possibilities:
    1.  Learn to use a widget framework such as Widget Factory or CpGears to make this possible
    2.  Take a look at the Infosemantics Event Handler Widget.  Not sure if it will meet all your needs, but it's worth a look.
    3.  Hire a Captivate Widget Developer to make this possible... and yes I am a Widget Developer (shameless plug )
    Hope that helps,
    Jim Leichliter

  • Load AS2 swf into AS3 swf problem

    I have a flash with AS3 and inside this swf i load in a AS2 swf.
    to load swf works just fine, but the problem is when i load this i want to go to
    a specific part of it, for example i want to go to frame 3 in the loaded swf.
    i must control this from the AS3 swf, does someone know if this is possible?
    thanks in advance

    so can i do like this then to go to frame 3 in my loaded swf?
    MovieClip(ldr.content).gotoAndStop(3); ?
    sorry for being such an airhead
    thanks for helping me out =)
    Date: Sun, 7 Jun 2009 10:25:09 -0600
    From: [email protected]
    To: [email protected]
    Subject: load AS2 swf into AS3 swf problem
    no.
    if, in your loaded swf, you have a function f1() on the loaded swf's main timeline and you load that swf using a loader (say ldr), use:
    MovieClip(ldr.content).f1();   // to call f1() in the loaded swf
    >

  • Calling a parent function when child .swf closes

    I am adding a child .swf from the parent with a simple button. If this button is then clicked multiple times, the child is added multiple times. So I added the ".visible = false"  to the button when clicked so the button cannot be clicked while the child is open.
    Now, there is "Close" button on the child .swf that uses "this.parent.parent.removeChild(this.parent);" and would now need to set the parent button back to ".visible = true".
    I have tried MovieClip.parent.parent.resetButton();  and  parent as MovieClip.resetButton(); and many variations of the code. I get no errors but the code doesn't work either.
    Any ideas?
    Thank you.

    Figured this out on my own (don't believe it) without the child/parent communication.
    When the parent's button is clicked, I'm checking to see if the child already exists. If so, it won't create the child again.
    I'd still like to know how to perform the communication between child and parent.

  • Dispatching and Event in Parent SWF & Receiving it in Child SWF

    Hi All...
          I  would like to receive an event(Dispatchd in Parent swf) in Child SWF,  the bold italic text represents the piece of coding i require help with
         //in PARENT SWF i have -----------------------------
            dispatchEvent(new Event("CloseDoors"))
        // in Child SWF --------------------------------
           here i need a code that catches the event dispatched in parent.addEventListener("closeDoors",closedoor)
           Please let me know if there are alternative ways to do it. I think some  people prefer to listen to the event also in Parent file and run
           the function in CHild from parent file....i would like to learn the  best practive to INFORM CHILDREN through a PARENT FILE...
         Thanks.

    Perfect....just to make sure i m taking care of it in a nice practical way....here is how i learned to access a file located in Child (researching other posts)
    is this the way you recommend it?
    (LoaderName.content as MovieClip).functionName(new Event("whatever"))
    and in Child File we have
    function functionName(e:Event)
    i have seen other ways of calling a function in Child Swf , like using EmbedSWF and etc. wanna make sure which one is a better practice. Thanks

  • Rendering of SWF Loader child SWFs

    I am using the swf loader with an Xcelsius OpenDoc link (http://<server>:8080/Xcelsius/opendoc/documentDownload?sIDType=CUID&iDocID=<CUID>&sKind=Flash&CELogonToken=<CELogonToken>)  and it works beautifully so long as the parent swf is also opened using and OpenDoc link.  However, if the parent swf is opened via InfoView, the child swf does not render properly (either way too large or too small).  Has anyone else come across this or have any ideas for resolution?
    Regards,
    Alison

    "whomba" <[email protected]> wrote in
    message
    news:glq6j0$b20$[email protected]..
    > Hello all,
    > I have a Flex app that loads in a swf using 'SWFLoader'
    tag. the SWFloader
    > and
    > the swf being loaded in are the same height and width
    (see attached code)
    > Now,
    > the SWF getting loaded in is also 468 X 351 however the
    designers that
    > made it
    > have crazy amount of random Movie Clips EVERYWHERE that
    isn't on the
    > stage. My
    > guess is that the actual height and width of the SWF is
    close to 1000 X
    > 1000.
    > When I load this SWF in to my SWFLoader it scales
    everything down so all
    > of the
    > MovieClips are inside of this SWFLoader rather than just
    the SWF's Stage.
    > Any
    > Suggestions?
    >
    > <mx:SWFLoader id="mainMovieSWF" height="351"
    width="468"
    > source="{mainMovieSrc}" scaleContent="false"/>
    Try wrapping it as a component with the Flex component kit.
    That way you
    get to specify the bounding box.
    HTH;
    Amy

  • Parent/child swf files

    Hello,
    Can a parent .swf listen for an event in a child .swf?
    Thanks!
    Erin

    Exactly how you add listener to anything.
    myLoadedMovie.addEventListener("eventType", myEventHadler);

  • Child of child swf not being unloaded

    I loaded an swf into an swfLoader using a bytearray. The child swf being loaded loads another swf within itself. When I run swfLoader.unloadAndStop() it removes the child swf but not the child swf's child. How can I unload both?

    You will have to custom code a way to tell the child SWF to unload its
    child.

  • Send varible vaue one swf to another(child) swf??

    Hi I have made my project in diffrent flash files but now i m stuck to get data from child.swf to index.swf.

    In your index file declare variables like
    var datafromchild:String="";
    and from your child swf write as:
    MovieClip(root).datafromchild="your name";
    MovieClip(root) depends upon the level sometimes it would be MovieClip(parent.parent).datafromchild="your name" based on the nested movieclips.
    This is a simplest method, but if level increases it will be worst to store and retrieve. also have others feedback also may be you will get some simple methods too.
    Note: there is no global variable in AS3 like AS2

  • Parent SWF controlling Child SWF variables

    1) The code below works but the browser sends an annoying
    alert message
    “Received Parent Message” and you are obliged to
    click OK before the program can run. How can it be fixed ?
    2) Why this code needs to use the
    ExternalInterface class if the Child SWF gets loaded and
    becomes incorporated in the Parent SWF ?
    3) Is there a
    simpler and more straightforward way for a Parent SWF to
    communicate with a Child SWF ?
    package
    import flash.external.ExternalInterface;
    import flash.display.Sprite;
    import flash.text.*;
    public class ChildMovie extends Sprite
    public function ChildMovie():void
    public function alert(msg:String):void
    ExternalInterface.call('alert', msg);
    txt.text = msg;
    package
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.display.LoaderInfo;
    import flash.display.Sprite;
    public class ParentMovie extends Sprite
    public function ParentMovie():void
    var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,
    onLoadComplete);
    loader.load(new URLRequest('ChildMovie.swf'));
    private function onLoadComplete(e:Event):void
    var loaderInfo:LoaderInfo = e.target as LoaderInfo;
    addChild(e.target.content);
    var swf:Object = loaderInfo.content;
    swf.x = 75;
    swf.y = 50;
    swf.alert('Received Parent Message');

    Hi,
    You can launch the SWF in new window with navigateToURL() available in flash.net package by passing the path of SWF as parameter to function as
    navigateToURL(new URLRequest(domainPath + "/appmanager/login.swf"));

Maybe you are looking for

  • Problems with Kensington Presenter

    Hi all, I recently bought a Kensington presenter (Kensington Presenter Expert Green Laser Presenter with Cursor Control and Memory) for my MacBook Air (working with OS X 10.9.3 (13D65)). The presenter works fine for up to 5 minutes and afterwards not

  • CAn any one supply this script

    Hi can any one supply this script for installing Oracle 11i... adautostg.pl In order to create a staging area... Help me guys...

  • Under CentOS 6 x64, Java Thread.sleep()/Object.wait() will be influenced.

    Under CentOS 6 x64, Java Thread.sleep()/Object.wait() will be influenced while changing OS time. I found a BUG in java bug list. The bug id is 6311057 with fixed status. But I find it still existing. Under CentOS6 x64 platform, on JDK1.6.0_33, the bu

  • Mail won't open when clicked

    Hi, this has been going on for sometime, I have been putting up with it BUT I have now had enough of it !!!!! I tap on the Mail Icon in the Dock, Mail doesnt Open, quite often there is what appears to be a Mail Window opening but it disappears as qui

  • My HD is not been identified. What can I do?

    My external is not been identified by Macbook. How can I fix it?