我每次按下按鈕都會設置一個狀態。然後它進入一個框架和動作腳本中,無論狀態如何,它都會向舞臺添加一個子項並再次更改狀態,但是當您再次單擊該按鈕時,子項將移除並且狀態將更改回到之前的狀態,並且相同孩子再次被添加。這裏是我的代碼:Actionscript 3.0,adobe flash cs6 - 刪除小孩
// first frame and will never come back to this one
function blueTurnValve(event:MouseEvent) // to go to the frame
{
gotoAndPlay("blue");
STATE = 1;
}
var redscreen:redfilling = new redfilling();
if (STATE == 2)
{
removeChild(redscreen);
STATE = 1;
}
if (STATE == 1)
{
addChildAt(redscreen,2);
STATE = 2;
}
//after the child was added
function blueTurnValve1(event:MouseEvent)
{
gotoAndPlay("blue");
}
,但它不會工作,我得到的輸出誤差(只刪除子前):
引發ArgumentError:錯誤#2025:提供的DisplayObject必須是來電者的孩子。 at flash.display :: MovieClip/gotoAndPlay() at p1_fla :: MainTimeline()在flash1顯示:: DisplayObjectContainer/removeChild() at p1_fla :: MainTimeline/frame2()[p1_fla.MainTimeline :: frame2:35] /blueTurnValve1()[p1_fla.MainTimeline::frame30:19]
我的代碼有什麼問題?
如果(STATE == 2){ removeChild之(redscreen); STATE = 1; } – JBin
Hiq在添加'redscreen'和刪除它之間經過了很長時間?什麼是'redscreen'cild? – Craig