|
|
Move the object - ActionScript Webmaster Tips, Knowledge Base Webmaster Tools
| Home > ActionScript > Move the object | |
| | Category | : ActionScript | | Written by | : Admin | | Date | : 2008-11-10 | | Rating | : 0 | Voted : 0 times | | Hit | : 41 | | | | |
| See how to move any object in flash 8 using the Action Script and cursor.
Step 1
Create a new flash document, choose Modify > Document (Ctrl+J), and set Width to 350 and Height to 250px.
Step 2
Double click on layer1 to rename its name in background. Then, insert a new layer and name it object.
Step 3
Take the Rectangle Tool (R), and draw a "rectangle" which will represent the "object". See the picture below.
Step 4
While your "object" is still selected, press F8 key (Convert to Symbol), and convert it into a Movie Clip.
Step 5
Double click on a new made Movie Clip, or choose right click and Edit in Place.
Step 6
Then, while your object is still selected, press again F8 key and convert it into a Button symbol.
Step 7
While your object is still selected, open the Action Script Panel (F9), and paste this script:
on (press) {
swapDepths(2 );
_root.cursor.swapDepths(3);
startDrag("");
}
on (release) {
stopDrag();
}
Step 8
Go back on the main scene (Scene1), click on the first frame of layer object, and in Action Script Panel, paste this script:
help = false;
Step 9
Duplicate your "object" few times if you like.
Step 10
Insert a new layer and name it cursor. Then, take the Text Tool (T), and type out of background "Move it". See the picture below.
Step 11
While your text (cursor) is still selected, press F8 key and convert it into a Movie Clip.
Step 12
After that, open the Properties Panel (Ctrl+F3), and under <Instance Name> type cursor.
Step 13
Then, select again the cursor, open the Action Script Panel (F9), and paste this script:
onClipEvent (load) {
}
onClipEvent (mouseMove) {
xm = getProperty (_root, _xmouse );
ym = getProperty (_root, _ymouse );
setProperty("_root.cursor", _x, xm);
setProperty("_root.cursor", _y, ym);
}
onClipEvent (mouseDown) {
with (_root.cursor) {
gotoAndStop("clench");
}
}
onClipEvent (mouseUp) {
with (_root.cursor) {
gotoAndStop("open");
}
}
We're done!
|
|