How to pass data to a Flex application using SWFObject 2.0
2009-11-12 21:43
441 查看
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 properlyDetailed 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 :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Load some parameters</title> </head> <body> <div id="componentBox"> <!-- alternate content --> <p>Woops, it seems you don't have Flash player installed, shame on you! ;-) </div> <script type="text/javascript" src="js/swfobject/swfobject.js"></script> <script type="text/javascript"> window.onload = function() { var params = { cookbook : "Flex", author : "Romain 'Palleas' Pouclet", version : "1.0", website : "http://www.adobe.com", air : "best technology ever!" } /* * Loading a SWF to my webpage * parameter #1 is the path to the SWF I want to load * parameter #2 is the id of the HTML container (here it's a div containing alternative content (in case Flash in not installed * or javascript is not activated * parameters #3 and #4 are the dimension of the application (here 500px x 500px) * parameter #4 is the required version to make the application work * parameter #5 is path to the express installer (it will install flash) * parameter #6 is an anonymous object containing my parameters */ swfobject.embedSWF("Parameters.swf","componentBox","500","500","9.0.0","js/swfobject/expressInstall.swf", params); } </script> </body> </html>
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 ?
相关文章推荐
- How To Submit Form Data by Using XMLHTTP or ServerXMLHTTP Object
- Big Data Counting: How to count a billion distinct objects using only 1.5KB of Memory
- Fast convolutional neural network training using selective data sampling: Application to hemorrhage
- How To Display Hierarchical Data by Using Nested Repeater Controls and Visual C# .NET(ZT)
- Silverlihgt 2.0 参考:如何在silverlihgt中使用右键(How to Right Click on a Silverlight Application.)
- How to set an IIS Application or AppPool to use ASP.NET 3.5 rather than 2.0
- How to pass javascript complex object to ASP.NET Web Api and MVC
- Oracle 11g Active Data Guard step by step: How to create a Physical Standby Database using RMAN
- How to package a jar/jad application to DRM using Motorola DRM toolkit
- How to use an Outlook Object Model from Visual C++ by using a #import statement
- Using a delegate to pass data between two forms.
- (ros/navigation)how to build a map using logged data 怎样用记录的数据创建地图
- How to correctly read data when using epoll_wait
- How to migrate data from another Mac using Mountain Lion and earlier
- [转]How to build a data storage and VM Server using comodity hardware and free software
- How to get spring application context object reference? - See more at: http://www.java2novice.com/sp
- How to set an IIS Application or AppPool to use ASP.NET 3.5 rather than 2.0
- Export DWG with ObjectData to ESRI shape file using AutoCAD Map 3D API
- how to select data in multiple datatables after using join,group by and order by in Linq
- How To Generate An XML File As A Target Datastore Using ODI In An Integration Interface ? [ID 454268