如何使用条件动态文本加载影片剪辑。如果别的

时间:2014-10-30 19:23:13

标签: if-statement load conditional movie clip

我有两个动态文本,它们都会生成数字。如果一个值的值大于另一个值,则必须加载一个影片剪辑,否则必须加载另一个影片剪辑。

同样重要的是要注意我需要准确选择要加载此影片剪辑的位置。

我创建了这段代码,但它无效。

btn01.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_27);

function fl_ClickToGoToAndStopAtFrame_27(event:MouseEvent):void
{


var texto.text;

function testGuess():void{

    if (parseInt(texto.text) == 8)


var fl_MyInstance_3:greenlight = new greenlight();
addChild(fl_MyInstance_3);          


    }}}

2 个答案:

答案 0 :(得分:0)

试试这个:

btn.addEventListener(MouseEvent.CLICK, btn_on_Press);

function btn_on_Press(e:MouseEvent):void {

    var clp_index = parseInt(txt_01.text) > parseInt(txt_02.text) ? 1 : 2
    var new_clp = clp_index == 1 ? new clp_01() : new clp_02()

    // to set the new_clp position
    new_clp.x = 250   // left position
    new_clp.y = 50    // top position

    addChild(new_clp)

}

上次修改:

stop()

var new_clp, new_clp2, new_clp3

var timer:Timer = new Timer(3000)
    timer.addEventListener(TimerEvent.TIMER, onTimer)
    timer.start()

function onTimer(evt:TimerEvent):void {

    var loader:URLLoader = new URLLoader(new URLRequest('bdaily.txt'))
        loader.addEventListener(Event.COMPLETE, function(e:Event){
            bdaily.text = loader.data
        })

    var loader1:URLLoader = new URLLoader(new URLRequest('bmtd.txt'))
        loader1.addEventListener(Event.COMPLETE, function(e:Event){
            bmtd.text = loader1.data
        })

    var loader2:URLLoader = new URLLoader(new URLRequest('bwtd.txt'))
        loader2.addEventListener(Event.COMPLETE, function(e:Event){
            bwtd.text = loader2.data
        })

    var loader3:URLLoader = new URLLoader(new URLRequest('basketdtarget.txt'))
        loader3.addEventListener(Event.COMPLETE, function(e:Event){
            basketdtarget.text = loader3.data
        })  

    var loader4:URLLoader = new URLLoader(new URLRequest('basketwtdtarget.txt'))
        loader4.addEventListener(Event.COMPLETE, function(e:Event){
            basketwtdtarget.text = loader4.data
        })  

    var loader5:URLLoader = new URLLoader(new URLRequest('basketmtdtarget.txt'))
        loader5.addEventListener(Event.COMPLETE, function(e:Event){
            basketmtdtarget.text = loader5.data
        })

    if(new_clp){
        new_clp.parent.removeChild(new_clp)
        new_clp = null
    }
    if(new_clp2){
        new_clp2.parent.removeChild(new_clp2)
        new_clp2 = null
    }
    if(new_clp3){
        new_clp3.parent.removeChild(new_clp3)
        new_clp3 = null
    }
    trace('new_clp : '+new_clp)
    trace('new_clp2 : '+new_clp2)
    trace('new_clp3 : '+new_clp3)

    var clp_index = parseInt(bdaily.text) >= parseInt(basketdtarget.text) ? 1 : 2
        new_clp = clp_index == 1 ? new clp_01() : new clp_02()
    addChild(new_clp)

    var clp_index2 = parseInt(bwtd.text) >= parseInt(basketwtdtarget.text) ? 1 : 2
        new_clp2 = clp_index2 == 1 ? new clp_03() : new clp_04()
    addChild(new_clp2)

    var clp_index3 = parseInt(bmtd.text) >= parseInt(basketmtdtarget.text) ? 1 : 2
        new_clp3 = clp_index3 == 1 ? new clp_05() : new clp_06()
    addChild(new_clp3)

}

这是最简单的方法,您可以稍后进行优化。

答案 1 :(得分:0)

stop();

// timer loading
var timer:Timer = new Timer(2500);
    timer.addEventListener(TimerEvent.TIMER, onTimer);
    timer.start();

    function onTimer(evt:TimerEvent):void {
//primeiro indicador parte
    var loader:URLLoader = new URLLoader(new URLRequest("bdaily.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void {
var loadedText:URLLoader = URLLoader(event.target);
bdaily.text = loadedText.data;
}

// segundo indicador.
var loader1:URLLoader = new URLLoader(new URLRequest("bmtd.txt"));
loader1.addEventListener(Event.COMPLETE, completeHandler1);

function completeHandler1(event:Event):void {
var loadedText1:URLLoader = URLLoader(event.target);
bmtd.text = loadedText1.data;
}

//terceiro indicador
var loader2:URLLoader = new URLLoader(new URLRequest("bwtd.txt"));
loader2.addEventListener(Event.COMPLETE, completeHandler2);

function completeHandler2(event:Event):void {
var loadedText2:URLLoader = URLLoader(event.target);
bwtd.text = loadedText2.data;
}

//terceiro indicador
var loader3:URLLoader = new URLLoader(new URLRequest("basketdtarget.txt"));
loader3.addEventListener(Event.COMPLETE, completeHandler3);

function completeHandler3(event:Event):void {
var loadedText3:URLLoader = URLLoader(event.target);
basketdtarget.text = loadedText3.data;
}


var loader4:URLLoader = new URLLoader(new URLRequest("basketwtdtarget.txt"));
loader4.addEventListener(Event.COMPLETE, completeHandler4);

function completeHandler4(event:Event):void {
var loadedText4:URLLoader = URLLoader(event.target);
basketwtdtarget.text = loadedText4.data;
}


var loader5:URLLoader = new URLLoader(new URLRequest("basketmtdtarget.txt"));
loader5.addEventListener(Event.COMPLETE, completeHandler5);

function completeHandler5(event:Event):void {
var loadedText5:URLLoader = URLLoader(event.target);
basketmtdtarget.text = loadedText5.data;
}

//condicionais para gerar movieclip condicional
var clp_index = parseInt(bdaily.text) >= parseInt(basketdtarget.text) ? 1 : 2
    var new_clp = clp_index == 1 ? new clp_01() : new clp_02()
    addChild(new_clp)

var clp_index2 = parseInt(bwtd.text) >= parseInt(basketwtdtarget.text) ? 1 : 2
    var new_clp2 = clp_index2 == 1 ? new clp_03() : new clp_04()
    addChild(new_clp2)

var clp_index3 = parseInt(bmtd.text) >= parseInt(basketmtdtarget.text) ? 1 : 2
    var new_clp3 = clp_index3 == 1 ? new clp_05() : new clp_06()
    addChild(new_clp3)

}