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

留言

這個網誌中的熱門文章

對於 Delphi 10.1 Berlin 推出的看法

IntraWeb 學習日記:【Login】