A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: submitting props to a swf when loading it into another swf

  1. #1
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159

    submitting props to a swf when loading it into another swf

    I have a group of swfs that if you submit a param when embedding, it loads that xml document for it's own settings. Kinda like this:

    <embed src="myMovie.swf?xmldoc=someXML.xml"... etc/>

    the swf then loads the file from xmldoc and alters itself pertaining to the params described in the xml.


    Now I have another Movie I want to load up a bunch of these swfs. But I want to pass it the param "xmldoc" as well when loading it via the Loader class. I've tried something like this:

    code:

    var loader:Loader = new Loader();
    loader.load(new URLRequest("myMovie.swf?xmldoc=someXML.xml"));



    Now I'm not surprised this doesn't work. But hey, it was worth a try. Anyways I'm trying to figure out how to submit this variable to the swf when loading it just like I can when embedding it into an html page.

    Any help?

  2. #2
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    no luck eh?

    darn-ded.

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    567
    Um, I'm just theorizing here, in your child swf:

    Code:
    var VarThatMayBePassesByURLorParentSwf:String;
    if (parent.root.loaderInfo.parameters.xmldoc) {
    VarThatMayBePassesByURLorParentSwf =   parent.root.loaderInfo.parameters.xmldoc;
    } else {
    VarThatMayBePassesByURLorParentSwf =   VariableDeclaredInParentSwf;
    }
    and VariableDeclaredInParentSwf should be declared in the parent class and be accessable by the child swf? I'm a bit of a novice here.

  4. #4
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    I don't think that's my issue. I need to some how grab this information dynamically.


    Let me try and reexplain it as the two places I've posted this got 0 responses (yet I'm an extremely active member of the other forum and help people as much as possible).


    I'm loading several DisplayObjects. Things like images, swfs, videos, etc. These all can be done with the "Loader" class easily by passing a URLRequest through with the destination of the object. Some of these things are static (like images, and videos). But swf's on the other hand can be more dynamic.

    For instance I've created several swf's that are fairly generic... i.e.

    http://www.lordofduct.com/FlashTest/.../pageFlip.html

    each page in that example is it's own swf that accepts an xml document to say what image, text, and other stuff to display in it.

    I need to know how to via the XML document let the swf know what XML document should be used for this instance of this swf. But keep in mind that their is a chance a swf will be loaded that doesn't require such an XML document.

    I know with PHP, javascript, and even the embed method in HTML allows me to pass these kinds of params easily to a swf via basic strings. But I don't know how to let AS3 pass it through using a string from an XML document.

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Posts
    567
    Do you require nested swfs? It might be easier to handle with Movieclips. Especially if you need to keep track of the loading processing of the images.

    So, there's 2 xml documents?

    Loop through your xml, set your variables and use a function to call the loader each iteration? The variables could contain the required secondary document. Or they could be ignored no xml is required or it is passed through the embed code.

  6. #6
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    because the swf's loaded up need to be dynamic. This week I want to launch the movie with these images, swfs, and videos... but next week I want it to be another group of them.

    Why recompile and upload a new file all together when I could just reuse this one and swap out the stuff via xml.



    But yeah I want to pass a second .xml document to the embedded swf as a prop of the loaderInfo.parameters object for that swf.
    Last edited by lordofduct; 06-26-2008 at 05:29 AM.

  7. #7
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    You could get a property from the parent swf like this...

    code in child swf
    Code:
    function initHandler(evt:Event):void
    {
    	// check if loaded inside a parent clip (else standalone)
    	if ((evt.currentTarget as LoaderInfo).applicationDomain.parentDomain)
    	{
    		var xmldoc:String = (parent.parent as MovieClip).xmldoc;
    		// load xml now you have the info...
    		trace(xmldoc);
    	}
    	else
    	{
    		trace("no parent swf");
    	}
    }
    this.loaderInfo.addEventListener(Event.INIT, initHandler);
    Alternatively, you can pass the property to the loaded swf or run a function in the loaded swf from the parent swf like this...

    code in parent swf

    Code:
    var xmldoc:String = "some.xml";
    
    var loader:Loader = new Loader();
    loader.load(new URLRequest("loadme.swf"));
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoaded); 
    addChild(loader);
    
    function swfLoaded(evt:Event):void
    {
    	// set property in loaded clip
    	(loader.content as MovieClip).xmldox = xmldoc;
    
    	// or
    	try
    	{
    		// run function in loaded clip
    		(loader.content as MovieClip).loadXML(xmldoc);
    	}
    	catch(err:Error)
    	{
    		// function not found
    		trace(err.toString());
    	}
    }
    note that if you set the property in the child swf like this, it will not be set until after the first frame is executed. So the function option might be better unless you only want to access the property from frame 2 onwards.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  8. #8
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    I was trying to avoid these kinds of things and loading it like I load them in html. My issue is I want any user using the gallery to be able to easily submit whatever they want as params to the swf like they do using it on its own. Just this time sticking it in the XML so it loads into this swf.

    But I guess I'll have to do something like this.

    Thanks anyways guys.
    Last edited by lordofduct; 06-26-2008 at 05:07 PM.

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