dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] Pass parameters from parent to child swf

  1. #1
    Senior Member flamedude's Avatar
    Join Date
    Jun 2003
    Location
    Vancouver, BC
    Posts
    252

    resolved [RESOLVED] Pass parameters from parent to child swf

    Hi guys,

    I'm really not getting anywhere with this at all.... I have made a piece of flash that runs on an xml document and now I need to pass a flash variable (via the html swfobject) to the flash to dictate this xml location. The variable is successfully passed if I embed the main swf straight into the swfobject.

    The problem is I am using a preloader swf to load the main swf onto the page and I can't seem to work out how to pass the variable (from swfobject) from the preloader to the main swf. Can anyone help me out?

    I've searched around and I just can't seem to work out a definitive answer that works.

    Thanks in advance,

    Steven.

  2. #2
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    in the preloader, just add the variables to the url string...

    new URL("http://domain/myswf.swf?something=something&blah=2&myvar=somethingelse");
    Search first, asked questions later.

  3. #3
    newb of many sorts Ralgoth's Avatar
    Join Date
    Apr 2002
    Posts
    466
    here's an example...

    PHP Code:
    var myVars:URLVariables = new URLVariables();
    myVars.var1 root.loaderInfo.parameters.var1;
    myVars.var2 root.loaderInfo.parameters.var2;
    myVars.var3 root.loaderInfo.parameters.var3;

    var 
    myLoader:Loader = new Loader();
    myLoader.contentLoaderInfo.addEventListener(Event.COMPLETEonCompleteHandler);
    myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESSonProgressHandler);
    myLoader.load(new URLRequest("http://mydomain/myswf.swf?"+myVars.toString())); 
    Then you would be able to load access them the same way in the main swf (root.loaderInfo.parameters.var1)

    edit: you may be able to push myVars into the URLRequest.data instead of converting it to a string, i haven't tried
    Last edited by Ralgoth; 09-08-2009 at 04:17 PM.
    Search first, asked questions later.

  4. #4
    Senior Member flamedude's Avatar
    Join Date
    Jun 2003
    Location
    Vancouver, BC
    Posts
    252
    Wow thank you very much Ralgoth! That worked perfectly. I had worked out a different method from another forum using MovieClip(parent.root) to get from the loaded swf back up to the loader swf to reach the flash vars but it was very very dirty code. This is much tidier and no coercion errors in sight.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center