views:

826

answers:

3

Hey everyone, today I'm trying to get a link to an XML file passed from the Object Embed code into my Flash movie. (Not using SWFobject). I have 1 swf file that should be able to connect to 3 different XML files.

Attempt 1


Below is the HTML code (I'm trying to get theXML path):

<div class="left">
<h2>300 x 353 Green Accent Color</h2>

<script type="text/javascript">
        AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','300','height','353','src','TEN','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','TEN' ); //end AC code
</script><noscript>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="353">
  <param name="movie" value="player.swf" />
  <param name="quality" value="high" />
  <param name="theXML" value="client_user.xml" />
  <embed src="TEN.swf" allowscriptaccess="always" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="353"></embed>
</object></noscript>

</div>


Document Class

private var theXML:String = root.loaderInfo.parameters.xmlPath;


public function TEN():void
{
    if (stage) init();
    else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void 
{
    removeEventListener(Event.ADDED_TO_STAGE, init);

    xmlLoader.addEventListener(Event.COMPLETE, xmlCompleteHandler);
    xmlLoader.load(new URLRequest(root.loaderInfo.parameters.xmlPath));

    loader = new BulkLoader("bulky");
    loader.logLevel = BulkLoader.LOG_INFO;
    loader.addEventListener(BulkLoader.COMPLETE, onBulkLoadComplete);
    loader.addEventListener(BulkLoader.PROGRESS, onBulkLoadProgress);
    //loader.add("client_user.xml",{id:"xmldata"});              //<- for TESTING
    //loader.add(theXML+".xml",{id:"xmldata"}); //<- for LIVE
    loader.add(xmlPath+".xml",{id:"xmldata"}); //<- for LIVE
    loader.start();
}



Attempt 2


HTML with different PARAM passing syntax:

<div class="right">
        <h2>520 x 477 Blue Accent Color</h2>
        <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','300','height','353','src','TEN','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','TEN' ); //end AC code
</script><noscript>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="353">
  <param name="movie" value="TEN.swf?xmlPath=520" />
  <param name="quality" value="high" />
  <param name="xmlPath" value="520.xml" />
  <embed src="TEN.swf" allowscriptaccess="always" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="353"></embed>
</object></noscript>
    </div>



Attempt 3


Flash Code Updated:

private var theXML:String = "";

private function init(e:Event = null):void 
{
    removeEventListener(Event.ADDED_TO_STAGE, init);

    theXML = stage.loaderInfo.parameters.xmlPath;

    loader = new BulkLoader("bulky");
    loader.logLevel = BulkLoader.LOG_INFO;
    loader.addEventListener(BulkLoader.COMPLETE, onBulkLoadComplete);
    loader.addEventListener(BulkLoader.PROGRESS, onBulkLoadProgress);
    //loader.add("client_user.xml",{id:"xmldata"}); //<- for TESTING
    loader.add(theXML,{id:"xmldata"}); //<- for LIVE
    //loader.add(theXML+".xml",{id:"xmldata"}); //<- for LIVE
    loader.start();
}

Updated HTML code:

<div class="right">
        <h2>520 x 477 Blue Accent Color</h2>
        <script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','300','height','353','src','TEN','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','TEN' ); //end AC code
</script><noscript>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="353">
  <param name="movie" value="TEN.swf?xmlPath=520.xml" />
  <param name="quality" value="high" />
  <param name="xmlPath" value="520.xml" />
  <embed src="TEN.swf?xmlPath=520.xml" allowscriptaccess="always" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="353"></embed>
</object></noscript>
    </div>

Right now it's not loading the XML file from the param :(

+1  A: 

Can you use SWFObject? Much easier to implement.

http://bowievanling.com/blog/using-flashvars-with-swfobject-20-and-as3/

Preston
No :( wish we could, but for this project we cannot use any Javascript
Leon
+3  A: 

Look at FlashVars--this is the standard way of passing variables through the object tags to the SWF.

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="353">
  <param name="movie" value="http://www.howdini.com/TEN/TEN.swf" />
  <param name="quality" value="high" />
  <param name="flashVars" value="theXML=client_user.xml" />
  <embed src="TEN.swf" 
         flashVars="theXML=client_user.xml"
         allowscriptaccess="always" 
         quality="high" 
         pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" 
         type="application/x-shockwave-flash" width="300" height="353">
  </embed>
</object>

Using FlashVars this way, or setting query parameters in the SWF's URL (TEN.SWF?theXML=client_user.xml), will fill in your loaderInfo.parameters field.


I'm used to Flex (where the FlashVars are stored in application.parameters, but in AS3, I think you'd use the loaderInfo:

// constructor
public function init():void {
    theXML = this.loaderInfo.parameters.theXML;
    ...
}
Michael Brewer-Davis
What is the correct corresponding Flash code for this method? I tried putting the variable in the embed tag, tried putting it after the TEN.swf?xmlPath=520.xml nothing is working :(
Leon
Michael is right - loaderInfo.parameters is an object whose properties and values mirror the flashvars - so loaderInfo.parameters.theXML would return 'client_user.xml'.
matt lohkamp
YES! :D Finally OMG thx :) I'm saving this HTML file
Leon
+1  A: 

Yep, just use swfobject! On html

<script>
swfobject.embedSWF("your-movie.swf", "yourdivid", "width", "height", "flashverion", "path to expressIntall.swf", {flashvar:"value", flashvar2:"value"}, {flashparam:"value", flashparam2:"value"});
</script>
<div id="yourdivid">Your alternative content or download links for flash player</div>

On Flash

var var1:Type = root.loaderInfo.parameters['flashvar'];
var var2:Type = root.loaderInfo.parameters['flashvar2'];
Eder Lima
Yeah I totally would have, but we can't use any JavaScript for the client :/
Leon