2015-03-13 40 views
2

我有一個代碼,我可以通過互聯網獲取圖像...我已經完成了它。我要補充到按鈕,一個提高,一個降低的間隔......在動作腳本2.0如何添加按鈕以減少和增加動作腳本2.0中的時間間隔sp_dump

import mx.transitions.*; 
import mx.transitions.easing.*; 
my_pb.mode = "manual"; 
this.createEmptyMovieClip("img_mc", 999); 
var my_mcl:MovieClipLoader = new MovieClipLoader(); 
var mclListenerbject = new Object(); 
mclListener.onLoadStart = function(target_mc:MovieClip) { 
    my_pb.label = "loading: "+target_mc._name; 
}; 
mclListener.onLoadProgress = function(target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number) { 
    var pctLoaded:Number = Math.ceil(100*(numBytesLoaded/numBytesTotal)); 
    my_pb.setProgress(numBytesLoaded, numBytesTotal); 
}; 
var number:Number = 2000; 
var myInterval = setInterval(testInterval, number); // 
function testInterval() { 
my_mcl.addListener(mclListener); 
my_mcl.loadClip("http://google.com/l5", img_mc); 
} 

我可以創建2個按鈕,但也有一些錯誤...

+0

什麼樣的錯誤?等等,爲什麼你還在使用AS2.0? – Raptor 2015-03-13 11:16:52

+0

我是新來的......所以我從2.0開始 – TOM 2015-03-13 11:19:04

+0

號請不要。 AS2.0已經在很多年前停產了,而AS3.0並不是AS2.0的直接升級版本(例如語法非常不同)。 – Raptor 2015-03-13 11:20:00

回答

2

如果你想改變setInterval功能的間隔,必須清除它,然後使用功能與新的區間值,就像這樣:

var delay:Number = 2000; 

var interval = setInterval(on_repeat, delay); 
function on_repeat() { 
    // instructions 
} 

fast.onPress = function(){ 
    clearInterval(interval); 
    interval = setInterval(on_repeat, delay - 1000); 
} 
slow.onPress = function(){ 
    clearInterval(interval); 
    interval = setInterval(on_repeat, delay + 1000); 
} 

但是,正如@Raptor說,我推薦你使用ActionScript 3代替舊的ActionScript 2.

例如,上面的代碼能夠簡單地通過一個Timer對象替換:

var delay:int = 2000; 

var timer:Timer = new Timer(delay); 
    timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent):void { 
     // instructions  
    }) 
    timer.start(); 

fast.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void { 
    timer.delay = delay - 1000; 
}) 

slow.addEventListener(MouseEvent.CLICK, function(e:MouseEvent):void { 
    timer.delay = delay + 1000; 
}) 

希望,可以幫助。

+0

@TOM沒有,因爲在父時間軸,你這樣做:'btn.onPress = function(){/ *指令* /}'這相當於:on(press)= function(){/ * instructions * /}'作爲按鈕動作。 – akmozo 2015-03-16 07:47:27

+0

@TOM我不知道你是如何包含你的按鈕,但在我的示例代碼中,我命名按鈕:快速和慢速,所以考慮到這一點。 – akmozo 2015-03-16 16:00:58

+0

@TOM驗證你的代碼,慢速按鈕有一個'+',快速按鈕有'-'。 – akmozo 2015-03-17 13:31:43

1
var current_loader:Number = 1;   
var current_img:Number = 0;    
this.createEmptyMovieClip('img_01', 999);    
this.createEmptyMovieClip('img_02', 998);    
img_01._x = img_01._y=img_02._x=img_02._y=20;    
    var loader:MovieClipLoader = new MovieClipLoader(); 

    var listener:Object = new Object();     
    listener.onLoadStart = function(target_mc:MovieClip) { 
}; 

listener.onLoadProgress = function(target_mc:MovieClip,  numBytesLoaded:Number, numBytesTotal:Number) { 
}; 


    listener.onLoadComplete = function(target_mc:MovieClip) {  
    if (target_mc._name == 'img_01') {    
    img_02._visible = false;    
    } else {     
    img_01._visible = false;    
    }     
}; 


var delay:Number = 2000;     
var interval = setInterval(load_image, delay);   
function load_image() { 
loader.addListener(listener);    
loader.loadClip("http://google.com/latimage.php?",  _root['img_0'+current_loader]);          
current_loader = current_loader == 1 ? 2 : 1;           
current_img = current_img == images.length-1 ? 0 : current_img+1; 
}     
    slow.onRelease = function() {    
    interval = setInterval(load_image, delay+1000);    
    trace(interval);    

};    
    fast.onRelease = function() {     
    clearInterval(interval);     
    interval = setInterval(load_image, delay-1000); 
    trace(interval);    

};    
image_load();