Connecting Tech Pros Worldwide Forums | Help | Site Map

How do you read FlashVar in ActionScript

nathj's Avatar
Expert
 
Join Date: May 2007
Location: North Tyneside
Posts: 857
#1: Jan 28 '09
Hi,

Well the title of the thread is the question. I have tried searching for this and after several days of getting nowhere with it I decided I would ask.

So here's the deal. I am using Flash 8, I have a movie that reads information from an XML file. The trick is that depending on a selection on my web page I want the move to read a different XML file. This sounds simple enough right?

I thought so, pass the variables over to the ActionScript then use a Switch statement to determine which XML file to load.

Here's the HTML

Expand|Select|Wrap|Line Numbers
  1. <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
  2. WIDTH="600" HEIGHT="450" id="MyMovieName">
  3. <PARAM NAME=movie VALUE="carousel6.swf">
  4. <PARAM NAME=quality VALUE=high>     
  5. <PARAM NAME=FlashVars VALUE="schoolID=2">
  6. <EMBED src="carousel6.swf" quality=high WIDTH="100%" HEIGHT="100%"
  7. NAME="People" ALIGN="" TYPE="application/x-shockwave-flash"
  8. PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
  9. </EMBED>
  10. </OBJECT>
  11.  
The in the ActionScript I have the following at the very top of the actionscript
Expand|Select|Wrap|Line Numbers
  1. import mx.utils.Delegate;
  2. import mx.transitions.Tween;
  3. import mx.transitions.easing.*;
  4.  
  5. var schoolID:Number = Number(schoolID);
  6.  
  7. var numOfItems:Number;
  8.  
Then a littel further down I have the following Switch statement:
Expand|Select|Wrap|Line Numbers
  1. switch(schoolID)
  2. {
  3.     case 1:
  4.         xml.load("test.xml");
  5.         break ;
  6.     case 2:
  7.         xml.load("icons.xml");
  8.         break;
  9. }
  10.  
When I view my page I get the flash object on the page but is not playing anything which suggests that it has dropped through the switch statement and loaded no XML file.

If I simply load an XML file it will work, using no parameters etc.

If anyone can help me out that would be great, I'll try to answer any questions but I am very new to all this stuff.

Many thanks
nathj

nathj's Avatar
Expert
 
Join Date: May 2007
Location: North Tyneside
Posts: 857
#2: Jan 28 '09

re: How do you read FlashVar in ActionScript


Hi again,

I've made a slight change to the logic but essentially the same issue. I now want to pass the xml file over as a parameter, cut the switch statement and load the parameter...
Expand|Select|Wrap|Line Numbers
  1. xml.load(myxmfile) ;
  2.  
Still totally stuck on this so please help me out.

Cheers
nathj
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#3: Feb 14 '09

re: How do you read FlashVar in ActionScript


As far as I remember, you just access it by the name you gave in your flash vars. Try doing a trace() on your variable to see the output and if you're accessing it correctly.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#4: Feb 14 '09

re: How do you read FlashVar in ActionScript


Also, your embed element doesn't have a 'flashvars' attribute. I don't remember perfectly, but IE doesn't recognise embed, but does recognise object (will skip embed), and firefox is the other way around (it may be the wrong way). So, you need your flash vars for each of the elements.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#5: Feb 14 '09

re: How do you read FlashVar in ActionScript


Check out this on embedding flash.

And while I'm here, check out these links below, if you want to conform to web standards.

http://ln.hixie.ch/?start=1081798064&count=1
http://www.alistapart.com/articles/flashsatay
Reply