How do you read FlashVar in ActionScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathj
    Recognized Expert Contributor
    • May 2007
    • 937

    How do you read FlashVar in ActionScript

    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

    Code:
    <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
    WIDTH="600" HEIGHT="450" id="MyMovieName">
    <PARAM NAME=movie VALUE="carousel6.swf">
    <PARAM NAME=quality VALUE=high>     
    <PARAM NAME=FlashVars VALUE="schoolID=2">
    <EMBED src="carousel6.swf" quality=high WIDTH="100%" HEIGHT="100%"
    NAME="People" ALIGN="" TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
    </EMBED>
    </OBJECT>
    The in the ActionScript I have the following at the very top of the actionscript
    Code:
    import mx.utils.Delegate;
    import mx.transitions.Tween;
    import mx.transitions.easing.*;
    
    var schoolID:Number = Number(schoolID);
    
    var numOfItems:Number;
    Then a littel further down I have the following Switch statement:
    Code:
    switch(schoolID)
    {
        case 1:
            xml.load("test.xml");
            break ;
        case 2:
            xml.load("icons.xml");
            break;
    }
    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
    Recognized Expert Contributor
    • May 2007
    • 937

    #2
    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...
    Code:
    xml.load(myxmfile) ;
    Still totally stuck on this so please help me out.

    Cheers
    nathj

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      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.

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        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.

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Check out this on embedding flash.

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


          By default, Macromedia Flash generates HTML that is invalid (but it works). Can you have your Flash and web standards, too? Drew McLellan has found a way to embed Flash content using only valid tag…
          Last edited by Markus; Feb 14 '09, 10:14 PM. Reason: Added some 'further reading'

          Comment

          Working...