如何在鼠标单击时交换Flash var数组?

时间:2011-02-04 15:37:12

标签: arrays flash actionscript-2

我有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;
}

1 个答案:

答案 0 :(得分: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);
}