2011-02-04 4 views
0

私はマウスクリックで別の配列のために交換したいFlash var配列を持っています。マウスクリックでFlash var配列を交換するにはどうすればよいですか?

現在、最初の配列を空のMCに完全にロードします。ユーザーがbuttonMCを押すと、var productTxt2にスワップする必要があります。私のコードは以下の通りです。

AS2コード:

var productTxt1 = new Array(
"Product Name 1", "Price 1", "Headline 1", "Copy 1"); 

var productTxt2 = new Array(
"Product Name 2", "Price 2", "Headline 2", "Copy 2"); 

_root.createEmptyMovieClip("productInfoMC", 0); 

with (productInfoMC){ 
    var txt1:TextField = createTextField("name", 1, 0, 0, 0, 0); 
    var txt2:TextField = createTextField("price", 2, 0, 0, 0, 0); 
    var txt3:TextField = createTextField("headline", 3, 0, 0, 0, 0); 
    var txt4:TextField = createTextField("copy", 4, 0, 0, 0, 0); 

    txt1.htmlText = _root.productTxt1[0]; 
    txt1.autoSize = true; 
    txt2.htmlText = _root.productTxt1[1]; 
    txt2.autoSize = true; 
    txt3.htmlText = _root.productTxt1[2]; 
    txt3.autoSize = true; 
    txt4.htmlText = _root.productTxt1[3]; 
    txt4.autoSize = true; 
} 

答えて

0
var productTxt1 = new Array(
"Product Name 1", "Price 1", "Headline 1", "Copy 1"); 

var productTxt2 = new Array(
"Product Name 2", "Price 2", "Headline 2", "Copy 2"); 

_root.createEmptyMovieClip("productInfoMC", 0); 

with (productInfoMC){ 
    var txt1:TextField = createTextField("name", 1, 0, 0, 0, 0); 
    var txt2:TextField = createTextField("price", 2, 0, 0, 0, 0); 
    var txt3:TextField = createTextField("headline", 3, 0, 0, 0, 0); 
    var txt4:TextField = createTextField("copy", 4, 0, 0, 0, 0); 
} 

var tfArr = new Array(txt1, txt2, txt3, txt4); 
applySettings(); 
updateText(productTxt1); 

function applySettings(){ 
    for(var i = 0; i < tfArr.length; i++){ 
     tfArr[i].html = true; 
     tfArr[i].autoSize = true; 
    } 
} 

function updateText(contentArr: Array){ 
    for(var u = 0; u < tfArr.length; u++){ 
     tfArr[u].htmlText = contentArr[u]; 
    } 
} 

buttonMC.onPress = function(){ 
    updateText(productTxt1[0] == tfArr[0].htmlText ? productTxt2 : productTxt1); 
} 
+0

ありがとう - これはほとんど動作します。ボタンをクリックすると、古い配列のテキストは消えますが、新しい配列のテキストは表示されません。 –

+0

@ Justin Cross - 試してみてください。buttonMC.onPress = function(){ \t var tmpArr:Array = productTxt1 [0] == tfArr [0] .htmlText? productTxt2:productTxt1; updateText(tmpArr); } ' – www0z0k

関連する問題