1 Reply Latest reply on Jul 24, 2009 4:09 PM by Gregory Lafrance

    Dynamically embedding swf using flex

    pratyus

      Hi,

       

      I am new to flex. I trying to build a simple application in flex in which a user clicks a button, to choose a file (.swf) from a file selection box. I want to show/render this swf file in the application.

       

      below is the code (in this the file is hardcoded)..

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >
         
         
          <mx:Script>
              <![CDATA[
                
                  public var refUploadFile:FileReference = new FileReference();
                  public var swfFileName:String = new String ();
                 
                  private function addFile() : void

                     {
                     refUploadFile.browse();
                     refUploadFile.addEventListener(Event.SELECT, selectedFileShow);
                     }

                 private function selectedFileShow(event:Event):void 

                     {
                     fileName = refUploadFile.name;
                     swfFileName = "D:/"+ refUploadFile.name;  //considering the file resides in D:
                     }
              ]]>
          </mx:Script>
             
          <mx:Button id="browse" x="69" y="21" label="Browse" click="addFile()" />

          <mx:Image source="@Embed('D:/Pratyus.swf')" y="40" >
         
         </mx:Application>

       

      How can I change this code so that "D:/Pratyus.swf" is a variable which gets the value of "swfFileName" whenever a file is selected. Once the file selection is done, only then it is rendered.

       

      Thanks!