Chapter 14 Example 2 actionscript.. forked:21favorite:2lines:58license : MIT License modified : 2009-11-05 18:15:58 Embed Tweet package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.filters.DropShadowFilter; public class ch14ex2 extends Sprite { protected const NUM_FILES:int = 10; protected var deleteBin:Sprite; public function ch14ex2() { deleteBin = makeDeleteBin(); //the delete bin should stay at the bottom addChildAt(deleteBin, 0); deleteBin.x = 15; deleteBin.y = 15; for (var i:int = 0; i < NUM_FILES; i++) { var file:Sprite = makeFile(); addChild(file); //randomize position by looking at available stage size file.x = Math.random() * (stage.stageWidth - file.width); file.y = Math.random() * (stage.stageHeight - file.height); //Sprites are InteractiveObjects file.addEventListener(MouseEvent.MOUSE_DOWN, onFileMouseDown); file.addEventListener(MouseEvent.MOUSE_UP, onFileMouseUp); } } protected function onFileMouseDown(event:MouseEvent):void { var file:Sprite = Sprite(event.target); file.startDrag(); //Sprites have simple drag methods //moving is relative change in position file.x -= 2; file.y -= 2; //all DisplayObjects support filters file.filters = [new DropShadowFilter(2, 45, 0, 0.2)]; setChildIndex(file, numChildren-1); //set child depth to the top } protected function onFileMouseUp(event:MouseEvent):void { var file:Sprite = Sprite(event.target); file.stopDrag(); //Sprites have simple drag methods file.x += 2; file.y += 2; file.filters = []; //see if it's over the delete bin if (deleteBin.hitTestObject(file)) { //and if so, remove from display list removeChild(file); } } protected function makeDeleteBin():Sprite { var s:Sprite = new Sprite(); //Sprites support vector drawing s.graphics.beginFill(0xff0000); s.graphics.drawRoundRect(0, 0, 55, 70, 16); s.graphics.endFill(); return s; } protected function makeFile():Sprite { var s:Sprite = new Sprite(); //Sprites support vector drawing s.graphics.beginFill(0xc0c0c0); s.graphics.lineStyle(0, 0x808080); s.graphics.drawRect(0, 0, 8.5, 11); s.graphics.endFill(); s.scaleX = s.scaleY = 3; //DisplayObjects support scaling s.buttonMode = true; //Sprites can act like buttons return s; } } } Code Fullscreen Preview Fullscreen bradsedito Louis as3bible display list filters target hitTestObject setChildIndex stopDrag startDrag addChildAt numChildren buttonMode DropShadowFilter MouseEvent addEventListener removeChild scaleY scaleX MouseEvent.MOUSE_UP height MouseEvent.MOUSE_DOWN width addChild sort new page view favorite forked pv178 forked from: Chapter 14 Exampl.. nishantrishu8935 forked:0 favorite:0lines:58 (diff:1) pv28 forked from: Chapter 14 Exampl.. markmatthewsphd forked:0 favorite:0lines:58 (diff:1) pv0 forked from: Chapter 14 Exampl.. meckmann0101 forked:0 favorite:0lines:58 (diff:1) pv43 forked from: Chapter 14 Exampl.. Kuba forked:0 favorite:0lines:58 (diff:1) pv49 forked from: Chapter 14 Exampl.. Aditya.Tomar forked:0 favorite:0lines:58 (diff:4) pv99 forked from: Chapter 14 Exampl.. Adam.Sikora forked:0 favorite:0lines:63 (diff:9) pv126 forked from: Chapter 14 Exampl.. mroveli forked:0 favorite:0lines:58 (diff:1) pv144 forked from: Chapter 14 Exampl.. helen forked:0 favorite:0lines:58 (diff:1) 1 2 3NEXT