2011/11/01

Flex 4 – FlexGlobals.topLevelApplication

在Flex 3读取HTML页面的flashvars的变量需要使用Application.application,在Flex 4 SDK里使用FlexGlobals.topLevelApplication代替了Application.application。 

Flex 4已经使用swfobject了: 


<script type="text/javascript"> 
    var swfVersionStr = "10.0.0"; 
    var xiSwfUrlStr = "playerProductInstall.swf"; 
    var flashvars = {}; 
    flashvars.firstname = "Nick"; 
    flashvars.lastname = "Danger"; 
    var params = {}; 
    params.quality = "high"; 
    params.bgcolor = "#ffffff"; 
    params.allowscriptaccess = "sameDomain"; 
    var attributes = {}; 
    attributes.id = "TestProject"; 
    attributes.name = "TestProject"; 
    attributes.align = "middle"; 
    swfobject.embedSWF( 
        "FlashVarTest.swf", "flashContent", "100%", "100%", swfVersionStr, 
        xiSwfUrlStr, flashvars, params, attributes); 
    swfobject.createCSS("#flashContent", "display:block;text-align:left;"); 
script>

读取flashvars中firstname和lastname变量的写法: 

var first_name : String = FlexGlobals.topLevelApplication.parameters.firstname;
var last_name : String = FlexGlobals.topLevelApplication.parameters.lastname;

在Flash Builder 4里用Flex 4 SDK开发时,如果还使用了Application.application,则会有提示这是Flex 3 SDK的写法。


文章來源:Flex 4 – FlexGlobals.topLevelApplication

沒有留言:

張貼留言