1 Reply Latest reply on Oct 16, 2009 1:12 PM by barney_r

    How to use FlashVars to initialize a Flex component?


      Hi all,


      I am trying to pass arguments dynamically from a JSP to an embedded Flex app using FlashVars. The values are being passed correctly, but when my Flex app is first initialized, the FlashVars have not been assigned yet. I need to use one of the FlashVars to set a property of one of my Flex components, but the FlashVars are null when the component is created. How can I do this? Do I have to wait until the Flex app has loaded before setting the attribute? How would I accomplish that? Thanks in advance for your help.

        • 1. Re: How to use FlashVars to initialize a Flex component?
          barney_r Level 1

          I was able to resolve this, so I thought I 'd share the answer in case someone else has a similar problem. Instead of declaring the component (which is also a DisplayObject) in MXML, I create it in the ActionScript method that gets called on the application's creationComplete method and set the property using the FlashVar at that point. Here's a quick example, using a custom class called MyDisplayObject and a FlashVar called myName:


          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initVars()">
                              private function initVars():void {
                                   myName = Application.application.parameters.myName;
                                   myDisplayObject:MyDisplayObject = new MyDisplayObject();
                                   myDisplayObject.name = myName;