views:

481

answers:

4

I have a flash movie that is being used for several websites. On each site I would like to specify a different XML file inside the markup. How do I grab that string and use it in ActionScript?

in markup i want to do this:

<object ...
   <param name=FlashVars value="urlXML=myXML.xml" />
</object>

in actionscript 3.0, im trying to do this:

var urlXML=_root.urlXML;

Currently when I do this, I get an error in output saying 'access of undefined property...' How am i supposed to grab that string?

A: 

Note: Adobe KB article

FlashVars must be assigned in both the OBJECT and EMBED tags in order to work on all browsers.

dirkgently
A: 

It should just be there--you don't need the _root. See this.

jeffamaphone
That was in AS2. But I found the solution. I needed this line of code:var urlXML = loaderInfo.parameters.urlXML;
Armitage
+1  A: 

That isn't how you access FlashVars in AS3. You need the root loaderInfo's parameter property, that houses any FlashVars that were tacked on.


var urlXML: String = root.loaderInfo.parameters.urlXML;
Bryan Grezeszak
this worked for me too:var urlXML = loaderInfo.parameters.urlXML;
Armitage
A: 

My first response... so here goes:

I have a small video player application I developed for McGill University Alumni. You can see it here: http://www.alumni.mcgill.ca/esol/holiday/2008/flash.php?giftCode=123456 It picks up a 'Gift Code' from the URL but you can always hard-code your .xml file.

Here are the object and embed (s) I use:

<embed src="mcgill_annual_fund200903.swf**?giftCode=<?php echo $giftCode; ?>**" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="680" height="550"></embed>

And with the .js embed script:

<script type="text/javascript">

AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','680','height','550','src','mcgill_annual_fund200903**?giftCode=**','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','mcgill_annual_fund200903?giftCode=','wmode','transparent' ); //end AC code

And then to retrieve the info in AS3:

//get the giftCode
var gCode:String;
var giftCode:String;
function loaderComplete(lEvent:Event){
    gCode = loaderInfo.loaderURL;
    giftCode = gCode.substr((gCode.indexOf("?giftCode=")+10));
    //giftCodeTxt.text= giftCode;
}