A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Do you know how to use FlashVars?

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Posts
    22

    Do you know how to use FlashVars?

    Hello

    I have just built a flash menu for a client who wanted an html page with some embedded flash. I am wondering how I make the buttons stay in their 'over' state when the user has clicked the button depending on a certain variable that is passed depending on the current page.

    I have done some research and seen that there is some additional html that takes place and changes the swf file name to something like 'menu.swf@button=1'.

    I know that this is something to do with FlashVars, but really am stuck. Please can someone help me with this?

    Thank you.

  2. #2
    Stupid Little Dreamer
    Join Date
    Aug 2000
    Location
    Toronto
    Posts
    583
    You can use FlashVars or simply append the variables to the url as a GET string. The only real difference is that with appending, the url of the swf as it shows up in a browser's cache still has the variable string attached to it, but I like doing it this way because this means it shows up like that in my site logs, so that can aid debugging.

    In either case, you must urlencode your string (replace spaces and special characters with their hex equivalent), and variables are separated by an ampersand -- all this is just your basic GET-string stuff.

    To use FlashVars, you specify FlashVars as another parameter in your object/embed code, meaning it has to go in two places. First, add an extra param line:
    Code:
    <param name = "FlashVars" value = "someVar=1&someOtherVar=hello" />
    Then, add the same info into the embed section (I've left off the start of it for brevity):
    Code:
     ... pluginspage="http://www.macromedia.com/go/getflashplayer" value = "someVar=1&someOtherVar=hello" />
    On the other hand, to simply append the variables, just change the url of the object and embed src:
    Code:
    [for IE] <param name="movie" value="myMovie.swf?someVar=1&someOtherVar=hello" />
    
    [for MZ] src="myMovie.swf?someVar=1&someOtherVar=hello"
    And then in your flash movie, simply reference the variables with this, ie this.someVar and this.someOtherVar.

    Hope that helps!
    If it weren't for the last minute, nothing would get done ...

  3. #3
    Junior Member
    Join Date
    Apr 2006
    Posts
    6
    I'm also having problems with FlashVars...

    I'm making an application using the FLVPlayback component and I'm trying to get FlashVars to pass the FLV's filename to the video player. For some reason I can't get FlashVars to pass any variables into flash.

    I'm using the trial version of Flash CS3 available at adobe.com. I even copy/pasted the example given in CS3's help file and it didn't work. Is there some sort of publishing setting or something I'm missing?

    Here's the active part of the code:

    cmpVideoPlayer.contentPath = this.SceneName;

    if (this.SceneName == "Scene1.flv") {
    nSomeNumber = 1.5;
    sSomeString = "Exposition";
    cmpVideoPlayer.totalTime = 752.6;
    }else if //A few more else if statements
    There's a bit more to the code, but this is the only part that calls the variables assigned by FlashVars.

    Here's the object tag from my html file (given by Flash's publish feature):

    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="320" height="280" id="VideoPlayer" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="allowFullScreen" value="false" />
    <param name="movie" value="VideoPlayer.swf" />
    <param name="FlashVars" value="SceneName=Scene2.flv" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <embed src="VideoPlayer.swf" FlashVars="SceneName=Scene2.flv" quality="high" bgcolor="#ffffff" width="320" height="280" name="VideoPlayer" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
    </object>
    I also tried using _level0.SceneName instead of this.SceneName to the same effect.

    Any thoughts or suggestions would be greatly appreciated - I'm completely stumped.
    Last edited by Diseased Kitten; 06-22-2007 at 05:03 AM.

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    I recommend using swfobject http://blog.deconcept.com/swfobject/
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Stupid Little Dreamer
    Join Date
    Aug 2000
    Location
    Toronto
    Posts
    583
    Diseased kitten (btw I hope you get better, lol),

    I'll admit I don't know why your code is failing, but have you tried passing info via the other method (appending to the URL itself)? Also, you might try adding a textfield to your movie and trace into it everything in level0 to see what's being passed. ie:
    Code:
    for (var item in _level0)
    {
         txOutput.text += "\nitem " + item + " = " + _level0 [item];
    }
    If it weren't for the last minute, nothing would get done ...

  6. #6
    Junior Member
    Join Date
    Apr 2006
    Posts
    6
    Thanks for the suggestions, guys. Unfortunately, SWFobject isn't an option (I'm making it for a friend - they don't want to include extraneous javascript files) and appending the variables directly to the URL itself doesn't work (again, I'm completely baffled by this).

    Here's some potentially helpful info:

    --I'm using the CS3 trial versional, with an AS 2.0 file.

    --I can get this to work PERFECTLY on Flash MX 2004 Professional. Unfortunately, since I have to use the FLVPlayback component, I can't use that version.

    --I followed the example in CS3's built-in help system for AS 2.0, and it didn't work. I even copied the code directly into my .fla and .html files, and still no success. (This is the example for FlashVars where you pass a URL to the variable 'myURL')

    --If I write the URL directly into the .fla, it works. For example, writing:

    var myURL = "http://weblogs.adobe.com/"

    displays the proper URL. Assigning this through FlashVars and by attaching it to the URL gives an "Undefined" value.


    Well, I'm sure a lot of you will be as stumped as I am. This is actually quite frustrating =/. Oh well, any help is appreciated, and thanks for your time!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center