2013-01-17 96 views
-1

我已經使用Actionscipt2.0做了一個拖動和匹配閃存的東西,但現在我需要將其更改爲3.0。我改變它後,閃光燈不能再拖動東西,任何人都可以看看代碼,看看我錯誤地將它轉換成了哪一部分。謝謝。Drag stuffs,Actionscript 2.0 to 3.0

的ActionScript 2.0版本:

stop(); 
var randomPositionFrame = int(Math.random()*9)+1; 
content_mc.gotoAndStop(randomPositionFrame); 
for(var i=1; i<=5; i++){ 
eval("content_mc.matching_term_"+i)._alpha = 0; 
eval("content_mc.matching_term_"+i).onPress = function(){ 
    if(this._currentframe == 1){ 
     this.startDrag(); 
    } 
} 
eval("content_mc.matching_term_"+i).onRelease = onMouseUp = function(){ 
    this.stopDrag(); 
} 

eval("content_mc.matching_desc_"+i)._alpha = 0; 
eval("content_mc.matching_desc_"+i).onPress = function(){ 
    if(this._currentframe == 1){ 
     this.startDrag(); 
    } 
} 
eval("content_mc.matching_desc_"+i).onRelease = onMouseUp = function(){ 
    this.stopDrag(); 
} 
} 

的ActionScript 3.0版本:

stop(); 
var randomPositionFrame = int(Math.random()*9)+1; 
content_mc.gotoAndStop(randomPositionFrame); 
for(var i=1; i<=5; i++){ 
this["content_mc.matching_term_"+i]._alpha = 0; 
this["content_mc.matching_term_"+i].addEventListener(MouseEvent.MOUSE_DOWN,function():void  { 
if(this._currentframe == 1){ 
     this.startDrag(); 
    } 
} 
); 

    this["content_mc.matching_term_"+i].addEventListener(MouseEvent.MOUSE_UP,function():void { 
stage.addEventListener(MouseEvent.MOUSE_UP, doMouseUp, false, 0, true); 

function doMouseUp($evt:MouseEvent):void 
{ 
this.stopDrag(); 
} 
} 
); 


this["content_mc.matching_desc_"+i]._alpha = 0; 
    this["content_mc.matching_term_"+i].addEventListener(MouseEvent.MOUSE_DOWN,function():void  { 
    if(this._currentframe == 1){ 
     this.startDrag(); 
    } 
} 
); 

this["content_mc.matching_desc_"+i].addEventListener(MouseEvent.MOUSE_UP,function():void { 
this.stopDrag(); 
} 
); 
} 
+0

http://stackoverflow.com/questions/14374089/actionscript-2-0-to-3-0-please-give-a-hand-am-i-converting-wrong的重複問題,其中一個適當的解決方案是發現 –

回答

0

在您的鼠標監聽,你必須得到該事件的目標/對象。意思是你應用你的聽衆的目標。

創建兩個監聽功能,並將其應用到你的addEventListener電話:

function mouseDownHandler(e:MouseEvent):void 
{ 
    var object = e.target; 
    object.startDrag(); 
} 

function mouseUpHandler(e:MouseEvent):void 
{ 
    var obj = e.target; 
    obj.stopDrag(); 
} 

使用的addEventListener這樣的:

yourObj.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); 
yourObj.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); 
+0

是否意味着我不能直接使用「this」?像「this.startDrag();」? – user1900121

+0

我不這麼認爲。它只是一個函數調用,而函數本身認爲**這個**與你的想法是不同的。我理解你的推理。但是在AS 3監聽器函數中需要參數。在你的情況下,一個MouseEvent。事件對象本身告訴你你需要知道什麼,在這種情況下是目標。 – Placeable

+0

我是否需要自己回報「對象」和「目標」? – user1900121

0

這將無法正常工作

this["content_mc.matching_term_"+i] 

您需要分別與每個對象交談。所以首先this然後content_mc

this.content_mc["matching_term_"+i] 

可能會有所幫助。

+0

它有幫助,非常感謝 – user1900121