如何加载带有条件动态文本的影片剪辑。如果别的
Posted
技术标签:
【中文标题】如何加载带有条件动态文本的影片剪辑。如果别的【英文标题】:How to Load movie clip with a conditional dynamic text. IF...else 【发布时间】:2014-10-30 19:23:12 【问题描述】:我有两个动态文本,它们都将生成数字。如果其中一个的值大于另一个,则必须加载一个影片剪辑,否则必须加载另一个影片剪辑。
还需要注意的是,我需要准确选择加载此影片剪辑的位置。
我创建了这段代码,但它不起作用。
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);
【问题讨论】:
【参考方案1】: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)
【讨论】:
【参考方案2】:试试这个:
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)
这是最简单的方法,您可以稍后对其进行优化。
【讨论】:
完美运行!如何控制影片剪辑的显示位置? 我创建了一个循环来检查即将到来的信息,问题是影片剪辑不断在另一个影片剪辑之前加载另一个影片剪辑,即使用大量 RAM。你能帮我改进代码吗?我需要卸载所有信息并执行 if...else 并再次加载。这是代码: 我创建了一个循环来检查即将到来的信息,问题是影片剪辑不断在另一个影片剪辑之前加载另一个影片剪辑,即使用大量 RAM。你能帮我改进代码吗?我需要卸载所有信息并执行 if...else 并再次加载 @d.Sierra 你好,很抱歉,因为我缺席了很多天,所以你能解释一下你想要什么吗? 嗨,没问题!你帮了我很多。您的代码对我有用,问题是我设置了一个循环代码以每 5 秒获取 .txt 文件,并且影片剪辑(红灯或绿灯标志)加载比较动态文本框中的数字。问题是影片剪辑被加载在另一个之上,并且消耗了大量的内存。我需要卸载所有影片剪辑并重新加载它们。以上是关于如何加载带有条件动态文本的影片剪辑。如果别的的主要内容,如果未能解决你的问题,请参考以下文章