How to pass data to a Flex application using SWFObject 2.0

 

Problem

I want to display a Flex application in my webpage and pass it some parameters?

 

Solution

I'll use the swfobject project which will allow me to display my application and pass it some parameters really properly

 

 

 

Detailed explanation<解决方法:>

Here is my Flex application, have you can see the "parseParameters" method is important. It will display the name and the value of every parameters I passed to my application :

package com.palleas
{
  import mx.controls.TextArea;
  import mx.events.FlexEvent;
 
  import spark.components.Application;
 
  public class Facade extends Application
  {
    protected var logBox:TextArea;
   
    public function Facade()
    {
      super();
      logBox = new TextArea();
      logBox.width = 500;
      logBox.height = 300;
      addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
    }
   
    protected function creationCompleteHandler(e:FlexEvent):void
    {
      removeEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
      addElement(logBox);
      parseParameters();
    }
   
    /**
    * This method display the name and the value
    * of every parameters passed to the Flex Application
    */
    protected function parseParameters():void
    {
      logBox.text = "";
      var currentParamIndex:uint = 1;
      for(var parameterName:String in parameters)
      {
        logBox.text += "Parameter #"+currentParamIndex + ": ";
        logBox.text += parameterName + " " + parameters[parameterName] + "/n";
        currentParamIndex++;
      }
    }
  }
}

My webpage is really cheap, all I want is my flex Application so :




 
  Load some parameters


 


   
   

Woops, it seems you don't have Flash player installed, shame on you! ;-)
 


 
 
 

Conclusion

As you can see, swfobject makes really easy to add a Flex application to a webpage and pass it some parameters properly. You don't have to write the object, embed, params HTML tags by yourself anymore, how cool is that ?

你可能感兴趣的:(Flash,Build,4)