Passing variables from parent flash into child?

Discussion in 'Software' started by shedlord, Jul 26, 2010.

  1. shedlord

    shedlord Private E-2

    Hi, wondering if anyone here can help.

    In brief, my question is, how can I pass a variable from a parent flash file to a child flash file which it calls?

    - More detailed version:

    We have a parent flash file which imports various child flash files based on instructions in an XML file. It's probably easier to see an example - http://www.opg2.co.uk/flash/yay.html - the text above each page, and the 'enlarge page' lightbox links are all in seperate flash files (one per double page) which are brought in, depending on the pages you are looking at, based on the instructions in an XML file which looks like this...

    <page ani_swf="pages/text1.swf">pages/white.jpg</page>
    <page ani_swf="pages/text1.swf">pages/0001.jpg</page>

    <page ani_swf="pages/text2.swf">pages/0002.jpg</page>
    <page ani_swf="pages/text2.swf">pages/0003.jpg</page>

    etc, where the swf is the header flash file containing the text and one or two lightbox links, and the jpg files are the page images that appear.

    We had to repeat the imported child flash file because of a glitch when you go backwards through the book otherwise.

    This system has been fine for us up until now but recently we've had to look at making it a dynamic system, so the content of the book can be varied depending on a variable being passed into the parent file via FlashVars...

    <param name="FlashVars" value="zone=1" />
    <embed src="newbook3.swf" FlashVars="zone=1" ....etc

    This makes the book load an xml file called "1"). This is fine, except we also need to vary the 'enlarge page' target images to match.

    The 'enlarge page' links are currently hard coded into each child flash file, like this...

    on (release){
    getURL("javascript:SWFDelegate('imagename.jpg','Example');");
    }

    - What we've tried so far:

    1. Trying to pass the variables in querystrings from the XML
    eg.

    <page ani_swf="pages/text2.swf?var1=image1&var2=image2">pages/0002.jpg</page>
    <page ani_swf="pages/text2.swf?var1=image1&var2=image2">pages/0003.jpg</page>

    with the child flash setting it's action like this...

    on (release){
    var image1 = var1 + ".jpg"
    getURL("javascript:SWFDelegate(image1,'Example');");
    }

    I'm not sure if the syntax here is correct. We have to add the ".jpg" in here because, as far as I understand it, you can't pass "." in a querystring.

    2. Passing the variables for the child into the parent

    I read somewhere that variables passed to a parent are automatically available to a child. Not sure if this is true, but it didn't work for me when I tried it like...

    <param name="FlashVars" value="zone=1?var1=image1&var2=image2" />
    <embed src="newbook3.swf" FlashVars="zone=1?var1=image1&var2=image2" ....etc

    Combined with...

    on (release){
    var image1 = var1 + ".jpg"
    getURL("javascript:SWFDelegate(image1,'Example');");
    }

    ...in the child button action.

    Sorry if this is a bit confusing. It definitely confuses me!

    Is there something really obvious we're missing here?

    thanks
     
  2. shedlord

    shedlord Private E-2

    To keep it simple, can anyone explain the way(s) to pass a variable from a parent flash to a child. Ignore the detail below!
     
    Last edited: Jul 27, 2010
  3. PC-XT

    PC-XT Master Sergeant

    Hello, again. I still don't do flash, yet, but I found some things you could try:
    http://www.webd.co.nz/flash/actionscript-3/as3-passing-variablesvalues-to-child-swf/ tells a way to do it.
    http://www.kirupa.com/forum/showthread.php?t=324709 tells more ways, with one working for the asker.
    http://www.kirupa.com/forum/showthread.php?t=289051 talks about passing with caching.
    http://board.flashkit.com/board/showthread.php?t=802182 gives a solution I think you already tried, and mentions something about MovieClip(parent.root) but doesn't give any code for it.
    Other pages that may have ideas if those don't work:
    http://www.actionscript.org/forums/showthread.php3?t=212798
    http://stackoverflow.com/questions/1226773/passing-one-variable-from-one-swf-to-another
    http://www.actionscript.org/forums/showthread.php3?t=210278
    Other sites I didn't load, but sound like they might have something:
    http://www.actionscript.org/forums/showthread.php3?t=243806
    http://www.actionscript.org/forums/showthread.php3?t=187394
    http://bytes.com/topic/flash/answers/826162-as3-passing-values-child-swf
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds