2011-10-26 92 views
0

當我引用它來獲取西班牙語或英語XML數據時,我需要將4個字母添加到變量名中。我正在嘗試在不寫if語句的情況下重用我的函數。將字母附加到變量名上

像這樣:

//two options for 
    var spa_my_videos:XMLList; 
    var eng_my_videos:XMLList; 

//APPEND OPTIONS 
    var spanishLang:String = "spa_"; 
    var englishLang:String = "eng_"; 

//CALL FUNCTION AND ADD APPEND OPTION 
    makePlayer (englishLang); 


    function makePlayer (lang:String):void { 

     my_player = new FLVPlayback(); 
     my_player.seekBar = SB; 
     my_player.playPauseButton = PPB; 
     my_player.volumeBar = VB; 

     my_player.x = video_x; 
     my_player.y = video_y; 
     my_player.width = 1023; 
     my_player.height = 630; 

     main_container.addChild (my_player); 

    //THIS IS WERE DEPENDING ON THE VALUE OF LANG I NEED TO USE THE spa_ or eng_ XML data 

     my_player.source = root_path + lang + my_videos[0][email protected]; 
    } 

回答

1

你的問題是一個利特爾混亂,但如果我理解正確的,你,您可以通過使用AS3上提供的Object [「variableName」]功能來解決此問題。 此功能允許您通過Object.variable或Object [「variable」]訪問變量,因此您可以在字符串上構建變量名稱,並使用它來引用您想要的內容。