17
Feb
09

Passing FlashVars using Flex template html

Adobe Livedoc (see here) indicates that you can pass flashvars in different ways through the URL or the flashvar object. I am using Flash Player 10 on Mozilla browser and it seems that the current player doesn’t work as explained.

It seems that there is only one way to pass the flash vars when using the template page that Flex builder 3.0 generates. You need to set it in the src under the javascript tag:


AC_FL_RunContent(
			"src", "${swf}?myName=Elad",
			"width", "${width}",
			"height", "${height}",
			"align", "middle",
			"id", "${application}",
			"quality", "high",
			"bgcolor", "${bgcolor}",
			"name", "${application}",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);

You can then easily read it in your Flex application:


var myName:String = mx.core.Application.application.parameters.myName;

I tested all the other options and nothing else seems to work. I also notices some other posts talking about the same issue, such as here:
http://flexblog.faratasystems.com/?m=200610

This issue may be related to the way the swf is deployed, in any case, I couldn’t get the examples from the livedoc to work. Remember to make the changes in the html-template folder so it will generate your template automatically every time you clean your project.

If anyone have more information, feel free to post it here.


18 Responses to “Passing FlashVars using Flex template html”


  1. 1 Anonymous Feb 25th, 2009 at 5:17 am

    Hi,

    if you use the default template javascript part
    you add to set your parameters like this:
    AC_FL_RunContent(

    “FlashVars”, “titi=444&url=woo”
    }

    If you delete the javascript part you have two ways do set parameters.
    This code works:

  2. 2 elad.ny Feb 25th, 2009 at 8:35 am

    I am not sure if I follow your comment. From my testing I noticed that without the Javascript part you can pass the flashvars through the FlashVars param without a problem, the issue starts with the javascript being thrown in the mix. I am not sure if it’s browser, JS or Flash 10 issue.

  3. 3 Chris Mar 5th, 2009 at 6:20 pm

    Works for me..

    Upgrade to Flex builder 3.2, as some fixes have been made in
    the templates (AC_OETags.js etc…) to support Flash 10.

  4. 4 tk Mar 30th, 2009 at 5:40 am

    hi,

    got mixed up with everything :-(

    i am new to flex.

    when passing params to swf through html, i have done and that works. didnt check it on Moz’ but IE and Avant it works just fine.

    now, i have this mxml project, that its output is swf, lets call it first project.
    i need to create another flex project (we will call it test project) that will include a list of options, and after the user selected an option it should invoke the first project passing it the selected option.

    how do i do that?

    from the samples i have found, i need to change the MXML of the first project to have bindable vars?

    thanks in advance for your kind help,
    tk

  5. 5 elad.ny Mar 30th, 2009 at 8:17 am

    I assume that the form is an HTML page. Once the user submit the form you can pass the variables through the URL.

  6. 6 tk Mar 31st, 2009 at 1:39 am

    i used swfloader from the test project to load the first project, passing it params. not so complicated as it seemed from all the talks about it.

    thanks anyway,
    tk

  7. 7 Killer Apr 6th, 2009 at 7:03 am

    Not sure why you had problems, the flashvars works as expected in the template. You must be doing something wrong.

  8. 8 malena mesarina May 8th, 2009 at 2:05 pm

    Hi Elad,

    thank you for the tip. I had the exact same problem as you, and the directions in the Adoble Flex 3 Help article “Paasing request data with flahVars properties” didnt’ work me either.
    Your way of doing it works though!

    -Malena

  9. 9 elad.ny May 9th, 2009 at 8:15 am

    Hi Malena, I am happy this post helped you.

  10. 10 Nash Jun 1st, 2009 at 2:11 pm
  11. 11 sidd Jun 3rd, 2009 at 12:59 am

    Thank you so much Elad,Your post really helped me

  12. 12 Wim Bervoets Jul 23rd, 2009 at 8:49 am

    Thanks for your post. I had the same issue!

  13. 13 Robert Aug 17th, 2009 at 3:41 pm

    Not working for me. No matter what I do in my wrapper, Flex Builder simply doesn’t know what the Application.application.parameters is. Actually that’s wrong. It compiles. But then when I place a watch on it in my creationComplete() method I always get:

    Application.application.parameters =
    No such variable: Application

    All examples in the docs have that variable existing at that point. Does it have to be set up later than creationComplete() or something?

  14. 14 elad.ny Aug 19th, 2009 at 11:15 am

    In Robert, in case you are using Flex 4 than you need to change the syntax to:
    mx.core.Application.application.parameters.myName;

    To:
    FlexGlobals.topLevelApplication.parameters.myName;

  15. 15 iamcoder Oct 8th, 2009 at 1:08 am

    Hi,

    Nice post. Thanks for sharing such nice information. Keep it up with good post.

    Ravindra
    http://www.rsdhariwal.com

  16. 16 Catalin M May 15th, 2010 at 3:50 am

    Thanks man! This saved me from a lot of headache!

  17. 17 zihao Jun 5th, 2010 at 6:50 pm

    Hi Elad, do you mean that the params have to be hard-coded in the html template page? If so how do I pass params to the Flex application dynamically?

  18. 18 Elad Elrom Jun 5th, 2010 at 8:05 pm

    Zihao - you can replace the hard-coded params with middle tier language.

Leave a Reply