开发者

How do I swap a Flash var array on mouse click?

I have Flash var array that I want to swap for another array on mouse click.

It currently loads the initial array into the empty MC perfectly. Now I need it to swap to var productTxt2 when the user presses buttonMC. My code is below.

AS2 code:

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);
开发者_StackOverflow
    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;
}


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜