2011-02-04 75 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

谢谢你 - 这几乎工程。当我点击按钮时,旧的数组文本消失,但新的数组文本不显示。 – 2011-02-05 23:42:09