1. 主場景上提供一個複製鈕duplicate_btn, 一個垃圾桶trashCan. 每按duplicate_btn一次可複製一個星星, 星星可被拖曳,若拖曳碰觸到垃圾桶,則被移除.
2. 元件庫有一個影片元件star, 兩個音效檔POP.WAV和ARCHER1.WAV, 右鍵選單/屬性, 分別自訂類別為_starMC、_popSound、_archerSound. (詳細說明可參考前一主題).
SWF預覽
3.第一影格AS3
//
duplicate_btn.buttonMode=true;
duplicate_btn.addEventListener(MouseEvent.CLICK, duplicate);
function duplicate(e:MouseEvent) :void{
var myStar:MovieClip = new _starMC();
addChild(myStar);
myStar.x=Math.ceil(Math.random()*(stage.stageWidth-60)+20);
myStar.y=Math.ceil(Math.random()*(stage.stageHeight-230)+20);
var POP:_popSound=new _popSound();
var channel:SoundChannel = POP.play();
//
myStar.addEventListener(MouseEvent.MOUSE_DOWN, dragStar);
myStar.addEventListener(MouseEvent.MOUSE_UP, releaseStar);
};
function dragStar(e:MouseEvent):void{
e.target.startDrag();
}
function releaseStar(e:MouseEvent):void{
var myStar:MovieClip = e.target as MovieClip;
stopDrag();
if(myStar.hitTestObject(trashCan)){
var ARCHER:_archerSound=new _archerSound();
var channel:SoundChannel = ARCHER.play();
removeChild(myStar);
}
}
1 則留言:
請問一下範例中的trashcan是影片片段嗎?
我照著範例做,測試時丟到垃圾桶卻無法使東西消失
張貼留言