2005-3
30
转载Jove兄的一片牛文:)
发信人: Jove (dVEuv), 信区: Flash
标 题: Flash不能直接操纵线程真不爽
发信站: 日月光华 (2005年03月27日16:38:27 星期天), 站内信件
常规编程语言中,可以调用Thread类的sleep,wait,notify方法甚至stop,resume
而这些目前AS2都不支持
若要几秒后执行一个操作
得call一下setInterval,并在callback方法中调用clearInterval
更无奈的是XML.load等方法是不阻塞的
function loadChildren(){
new xml();
xml.onLoad=function(){
//parse
}
xml.load()
}
function main(){
if(notLoaded)
loadChildren();
render()
}
new xml();
xml.onLoad=function(){
//parse
}
xml.load()
}
function main(){
if(notLoaded)
loadChildren();
render()
}
往往render()方法需要loadChildren把数据先加载完
因为xml.load()是不阻塞的,如果这样写render()往往会执行失败
习惯了Java等语言,我们会写段代码,等xml.load执行完再退出loadChildren
如
while(xml.loaded==false)
sleep(100)
sleep(100)
但目前的解决方法只好把render()这个callback放在xml.onLoad中,代码比较混乱
//workaround
function loadChildren(callback,context){
new xml();
xml.onLoad=function(){
function loadChildren(callback,context){
new xml();
xml.onLoad=function(){
//parse
if(calback!=null)
callback.call(context)
}
xml.load()
}
function main(){
if(notLoaded)
loadChildren(render,this);
else
render()
}[/code]
本文来自:http://www.awflasher.com/blog/archives/141
还没找到您要的东西?Google试试看吧,
Google更注重原创、时效性好的文章:
Google更注重原创、时效性好的文章:
| 相关阅读 | 本月十大 |



