Use startDrag, stopDrag, _droptarget, onPress and onRelease functions to simulate virtual trash.
This tutorial is advanced, you have to understand basic commands of Flash Designer.
Download source project t1049.zip (86 kb)
- Launch Flash Designer and set movie dimensions 300 x 300.
- Create 4 blank frames with "Frame" > "New" so you have "Frame 1" to "Frame 5" in the frame list.
- Download t1049.zip file and extract trash images.
- Import image "pieceofpaper.gif" (File > Import Image) and move it outside visible area.
- Convert it to sprite (Edit > Convert to Sprite), name it "Garbage" and check "ActionScript" target (Item > Placement Properties)
- Import image "opentrash.gif" and move it to X:170, Y:118 (Edit > Move To) .
- Draw an ellipse over the hole of the trash. Set fill color to black, 1% opacity, no line
- Convert it to sprite, name it "Hole" and check "ActionScript" target
- Add the text "Put all papers into trash"
- Add Frame ActionScript (Frame > ActionScript):
maxpapers=1;
- Add the text "GET READY!"
- Set background to "Frame 1"
Frame 3
- Set frame delay to "Stop"
- Set background to "Frame 1"
- Import "laser.wav" sound and set the frame sound
- Add Frame ActionScript:
maxpapers = maxpapers * 2; // at each run increase the number of pieces
collected = 0; // count collected items
function checkifallcollected()
{
// check if all items are collected and go to congratulations frame
if(collected==maxpapers) gotoAndPlay("Frame 4");
}
// this array will hold all pieces
var garbages = new Array();
// create maxpapers pieces
for(i=0;i<maxpapers;i++)
{
// create new instance of the paper
garbage[i] = Garbage.duplicateMovieClip("garbage"+i,100+i);
// put it in random place and random rotation
garbage[i]._x = 30+100*Math.random();
garbage[i]._y = 30+200*Math.random();
garbage[i]._rotation = 360*Math.random();
// define mouse events
garbage[i].onPress=function() { this.startDrag();};
garbage[i].onRelease=function()
{
// check if this piece hits the hole
if(this._droptarget=="/Hole") {this.removeMovieClip();collected++;}
stopDrag();
checkifallcollected();
};
}
- Import "elecshot.wav" sound and set the frame sound
- Import image "closedtrash.gif" and move it to X:174, Y:163.
- Set frame delay to 3 seconds
- Set background to "Frame 4"
- Set loop to frame 2 ("Frame" > "Loop" command)
- Import "clap.wav" sound and set the frame sound
No comments:
Post a Comment