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"));

Similar Messages

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

  • RemoveChild in parent.swf from child.swf (AS3)

    Hi! How do I remove a child from a parent timeline with an externally-loaded swf? Specifically, I have a main.swf that loads movie_1.swf and movie_2.swf. In the movie_1.swf, I have a button to remove movie_2.swf from main.swf.
    //--------- main.swf code:
    var loader1:Loader = new Loader();
    var loader2:Loader = new Loader();
    loader1.load(new URLRequest("movie_1.swf"));
    loader2.load(new URLRequest("movie_2.swf"));
    addChild(loader1);
    addChild(loader2);
    //------------- movie_1.swf code:
    removeMovie2_btn.addEventListener(MouseEvent.CLICK , removeMovie2);
    function removeMovie2(event:MouseEvent):void
    this.parent.parent.removeChild(this.loader2); // this does not work (get error code 2007, "Parameter child must be non-null")
    // Thank you!

    Here's how your code will change:
    //--------- main.swf code:
    var loader1:Loader = new Loader();
    var loader2:Loader = new Loader();
    loader1.contentLoaderInfo.addEventListener(Event.COMPLETE, assignMovie1Listener);
    loader1.load(new URLRequest("movie_1.swf"));
    loader2.load(new URLRequest("movie_2.swf"));
    addChild(loader1);
    addChild(loader2);
    function assignMovie1Listener(evt:Event):void {
          MovieClip(evt.currentTarget.content).addEventListener("eventTriggered", removeLoader2);
    function removeLoader2(evt:Event):void {
          loader2.unloadAndStop();
          removeChild(loader2);
    //------------- movie_1.swf code:
    removeMovie2_btn.addEventListener(MouseEvent.CLICK , removeMovie2);
    function removeMovie2(event:MouseEvent):void
          dispatchEvent(new Event("eventTriggered"));

  • 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

  • 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

  • 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

  • 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);

  • Problem:  Unable to call a function in parent swf from the child swf.

    I am working on a site right now that has a parent loader
    (all it contains are the menu bar [which is as3 tweened] and the
    functions for calling all of the other pages.) The problem that I
    am having right now, are some of the internal or child pages, need
    to call functions that are in the parent loader. For what ever
    reason, I am unable to do any of that.
    I have attached the code so you can look at that.
    Let me see if I can explain it any better.
    The code I just posted is for the Main Stage swf called
    loader.swf. It has the menu, and all the functions that control the
    menu's movement and when to load all the other swfs. The easiest
    way for me to ask this, is to show you.
    click
    http://dev.locallinux.com/mystictan/layout2.html
    When you get there, you will see the menu bar, and it is
    loading home.swf onto the stage behind the menu.
    Mouse over "The Perfect Tan" and click on "1: Base"
    You will notice it just loaded a new swf called ptbase.swf.
    Well in that swf is a button for "Products" That button
    basically needs to take you to "Products > 1: Base" on the menu
    (not working yet, I know. But theres no point in me making that,
    until I could get this working"
    What I would like is when you click on "Products" in
    ptbase.swf, it calls the function clickedProductsBase(), which does
    its thing. But that function is back in the loader.swf. Does that
    make sence?
    What am I missing here?

    RyanORo, thank you very much for your response.
    I try that, and I get this sort of error when I click on it:
    TypeError: Error #1006: fwd is not a function.
    at ptbase_fla::MainTimeline/testing()
    I know all that code that I posted was a bith much, but here
    is the movie loading part:
    function loadComplete(event:Event):void
    loaderbar.visible = false;
    mainbody.removeChild(thisMC);
    thisMC = MovieClip(myloader.content);
    myloader.unload();
    mainbody.addChild(thisMC);
    thisMC.gotoAndStop(1);
    TransitionManager.start(thisMC, {type:Fade,
    direction:Transition.IN, duration:5, easing:Strong.easeOut});
    mainbody is an empty mc under the menu, so that the loaded
    swf file appears under the menu.
    You know what, scratch all that . *MOOWHA* I could KISS you
    right now. "(parent as MovieClip).clickedProductsBase()" did not
    work because it was calling it out of the wrong parent. Just did
    "(this.parent.parent as MovieClip).clickedProductsBase()" and that
    did the magic I needed. Thanks...

  • 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

  • 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);

  • (AS3) Controlling Loaded SWF

    I am trying to control a loaded .swf with the parent .swf. I
    do not know how to call the loaded .swf. I know how to control the
    parent with the child, but not the other way around. any
    suggestions would be great. thanks!

    call on the Loader object where the movie is being held.
    You'll need to typecast like this....
    MovieClip(Loader.contentLoaderInfo.content). My recommendation is
    to store that path to a variable
    var myLoadedMovie:MovieClip = MovieClip(
    varNameOfMyLoader.contentLoaderInfo.content);
    change out the varNameOfMyLoader with the proper variable
    name and you should be able to target the movieclip as you would
    have done in AS2.

  • 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"));

  • 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

  • Attach mc's from parent SWF to loaded SWF

    I've got a movie (parent) that loads several other SWFs
    (children). I need for the parent SWF to attach movie's to the
    child SWFs from it's library - but i can't get it to work.
    Is there a way to do this?

    If the children are loaded into empty clips, they can be
    addressed via the instance name of the empty MC, and you can use
    holderMC.attachMovie("linkageID","newName",depth);
    to attach the symbol with "linkageID" to the MC loaded into
    the instance "holderMC".
    hth,
    blemmo

Maybe you are looking for

  • Qosmio X770-n404 How to get illumination to stick ON in Bios?

    Just received a brand new Qosmio X770-n404 from toshiba last week The lighted keyboard words fine when turn on However when turned off, and illumination set in BIOS to on, it wont stay on after windows starts I go back to Bios and it says illuminatio

  • Google safe browsing service is unavailable, no updates have occurred in 5 days

    this message appears on safary/prefferences/security/under fraudulent sites google safe browsing service is unavailable, no updates have occurred in 5 days?? help please!

  • Form Submits twice with IE

    Hi, my problem is that my form is submitted twice when using IE 7, but only once on firefox as desired. The steps my jsp app takes are: 1. submit details 2. validate details 3. submit details to database 4. faces-config navigates to appropriate downl

  • AAA and 3560 Switch + CNA

    Hi Has anyone got this to work? CNA. (Cisco Networks Assistants) and AAA (Tacacs+) on a 3560 switch. I can’t get the CNA to work in this setup but it works fine on together with 3500XL and 3550 serie switch. With the same parameter. this is the aaa c

  • ITunes 7.3 installation failed (Windows XP)

    While installing iTunes 7.3 on my Windows XP computer, the installation failed because the installer didn't have sufficient privileges to modify AppleMobileDeviceHelper.exe. I've tried uninstalling a previous version of iTunes and reinstalling it; I'