Search code examples
phpflashactionscript-3readfileurl-parameters

how can i load a swf into another swf using php readfile and retain the url parameters?


I am using php to read a file (specified by a cookie on the users machine) with the function readfile(). the file I am reading is an actionscript 3 flash file that depends on a configuration file appended to the url to function properly.

ex: http://www.pathToFlash.com/file.swf?CONFIG_URL=http://www.pathToConfig.com/config.xml

When I use readfile - the headers are set properly and the swf is returned to the browser which then runs it. I have discovered that using this method the config file (CONFIG_URL) has to be appended to the php file's url to be read properly by the swf - as the swf considers the path to the php file it's own.

This is fine when these are the only two elements involved - but when loading the php>read(swf) combination into another swf - the 'read' swf returns a url that is null (using this.root.loaderInfo.url) and therefore fails to execute properly as there is no config file (CONFIG_URL).

My question is: how can I load in a swf file from a php page (using readfile, fopen, whatever) and pass in $get parameters?


Solution

  • First of all:this.root.loaderInfo.url needs to be: this.root.loaderInfo.parameters.url.

    Second of all root.loaderInfo.parameters can be only accessed only from root swf. This means that you can not say inside swf to php: load.php?swf=second.swf&someParameter=1234, and parse some parameter for the loaded swf directly.

    The solution ( there is more thant one ) is:

    1. You need to set all this parameters for the root.swf ( when you loading it )

    mainConfig=xml/config.xml secondSWFconfig=xml/secondconfig.xml

    and etc...

    1. in the second.swf which will be loaded by root.swf you need to create function:

      public function set parameters ( value : Object ) { // here all the assigment of the parameters }

    2. In the root.swf function which is launched after second.swf is loaded:

      private function onSecondSWFLoaded ( e : Event ) : void { e.currentTarget.content['parameters'] = this.root.loaderInfo.parameters; }

    ANd then in the second swf you will be gettin these parameters and after them you can launch everything you need.

    regards.