3 Replies Latest reply on Jan 9, 2007 8:27 AM by forty6n2

    passing variables to an swf

    forty6n2
      I want to pass some variables at runtime to an swf I've created in Flex. The swf uses no MXML at all. I compiled it straight from an AS3 class. I've tried url encoding the variables (externalSWF.swf?var1=value&var2=value...) and then accessing them inside the swf using the Application.application.var1, but I can't seem to get it to work. Since the external swf uses no MXML at all, is the Application object even available? Any help would be appreciated.
        • 1. Re: passing variables to an swf
          Macys_Mike
          forty6n2,
          I tried to do the same thing, eventually after much searching I ran across something called flashVars. Essentially, you can pass values into flex and then do what ever you want with them. I wrapped my .swf file in an .asp page so that I could pass in the userID and ip address.

          Example:
          <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
          id="MiscControls" width="362" height="280"
          codebase=" http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
          <param name='flashVars' value='myName=<%= Response.Write(Request.ServerVariables("REMOTE_ADDR")) %>&myIP=<%= Response.Write(Request.ServerVariables("LOGON_USER")) %>'/>
          <param name="movie" value="MiscControls.swf" />
          <param name="quality" value="high" />
          <param name="bgcolor" value="#869ca7" />
          <param name="allowScriptAccess" value="sameDomain" />
          <embed src="MiscControls.swf" quality="high" bgcolor="#869ca7"
          width="362" height="280" name="MiscControls" align="middle"
          play="true"
          loop="false"
          quality="high"
          allowScriptAccess="sameDomain"
          type="application/x-shockwave-flash"
          pluginspage=" http://www.adobe.com/go/getflashplayer">
          </embed>
          </object>


          Good luck!
          - Mike
          • 2. Re: passing variables to an swf
            cardinalsupport Level 1
            You should also check out swfObject which was built to handle flash detection on browser and better support for displaying/placement of flash movies but also has a very nice and easy to use method for passing flashvars. Once they are passed you should be able to call them via actionscript in your swf file. here is more info on this: http://blog.deconcept.com/swfobject/

            s
            • 3. Re: passing variables to an swf
              forty6n2 Level 1
              Thanks for the response. I did come across Flashvars in my searching, but I failed to mention that I would need to load this external swf directly back into the flex application using the SWFLoader. I cannot have an ASP or HTML wrapper. In this case, is Flashvars still applicable? or is there another route you may suggest. Thanks again!