Jason's Tip Sheets

click here for Actionscript 3 transition guide

Copy and paste the below code to the Actions panel (window/actions) in flash
ACTIONSCRIPT2:
FRAME SCRIPT:

stop();
stopAllSounds();

BUTTON SCRIPT
on (press) {nextFrame();
}
on (release) {gotoAndPlay(1); }
on (release) {gotoAndPlay("INSERT SCENE NAME HERE", 1); }
on (press) {getURL(“http://www.mywebsite.com”); }

on (press) {getURL(“mailto:YOUREMAILADDRESS@SERVICE.COM”); }

DRAGGABLE MOVIE CLIP/BUTTON:
on (press) {
startDrag(this.INSTANCE NAME HERE);
}
on (release) {
stopDrag(this.INSTANCE NAME HERE);
} FOR A TARGET TO ROLL-OVER using the above movie clip:
on (rollOver)
{
stopDrag();
}

*CUSTOM CURSOR: CONVERT YOUR SYMBOL TO A MOVIE CLIP. PUT INSTANCE ON STAGE AND SELECT THE MOVIE CLIP:
onClipEvent (mouseMove) {
Mouse.hide();
this.onMouseMove = function()
{
this._x = _parent._xmouse;
this._y = _parent._ymouse;
updateAfterEvent();
};
}

*ANOTHER METHOD (FRAME ACTIONSCRIPT):
(crosshair is the named instance)
Mouse.hide();
crosshair.startDrag(true);

TO DISPLAY MOUSE CO-ORDINATES
(in a dynamic text field instance):

_root.onMouseMove = function() {
coordsDisplay.text = "X: " + _xmouse + "\nY: " + _ymouse;
}

*CAUTION! both of these methods will only trigger buttons when UNDER the button layer.
Make a copy of that mouse/cursor layer to put above or use another method,DRAG/TARGET below)


I came up with a sort-of solution...
I added the stopDrag as below then made the buttons into named instances
and when they were hit by the named instance of the cursor it executes the
code. NEXTMC is the named instance of my next scene button, cursormc is the cursor instance.
(this is also FRAME script).


Mouse.hide();
cursormc.startDrag(true);

cursormc.onRelease = function() {
this.stopDrag();

if (eval(this._droptarget) == nextmc) {
gotoAndPlay("Scene 2", 1);
}
};

MORE INTERACTIVITY:
You can use the global startDrag() function or the MovieClip.startDrag() method to make a movie clip draggable. For example, you can make a draggable movie clip for games, drag-and-drop functions, customizable interfaces, scroll bars, and sliders.

A movie clip remains draggable until explicitly stopped by stopDrag() or until another movie clip is targeted with startDrag().
Only one movie clip at a time can be dragged in a SWF file.

To create more complicated drag-and-drop behavior, you can evaluate the _droptarget property of the movie clip being dragged. For example, you might examine the _droptarget property to see if the movie clip was dragged onto a specific movie clip (such as a "trash can" movie clip) and then trigger another action, as shown in the following example:

// Drag a piece of garbage.
garbage_mc.onPress = function() {
this.startDrag(false);
};
// When the garbage is dragged over the trashcan, make it invisible.
garbage_mc.onRelease = function() {
this.stopDrag();
// Convert the slash notation to dot notation using eval.
if (eval(this._droptarget) == trashcan_mc) {
garbage_mc._visible = false;
}
};
-------
Changing movie clip position and appearance
To change the properties of a movie clip as it plays, write a statement that assigns a value to a property or use the setProperty() function. For example, the following code sets the rotation of instance mc to 45:
my_mc._rotation = 45;

This is equivalent to the following code, which uses the setProperty() function:
setProperty("my_mc", _rotation, 45);

Some properties, called read-only properties, have values that you can read but cannot set. (These properties are specified as read-only in their ActionScript 2.0 Language Reference entries.) The following are read-only properties: _currentframe, _droptarget, _framesloaded, _parent, _target, _totalframes, _url, _xmouse, and _ymouse.

You can write statements to set any property that is not read-only. The following statement sets the _alpha property of the wheel_mc movie clip instance, which is a child of the car_mc instance:car_mc.wheel_mc._alpha = 50;

In addition, you can write statements that get the value of a movie clip property. For example, the following statement gets the value of the _xmouse property on the current level's timeline and sets the _x property of the my_mc instance to that value:

this.onEnterFrame = function() {
my_mc._x = _root._xmouse;
};
This is equivalent to the following code, which uses the getProperty() function:this.onEnterFrame = function() {
my_mc._x = getProperty(_root, _xmouse);
};


The _x, _y, _rotation, _xscale, _yscale, _height, _width, _alpha, and _visible properties are affected by transformations on the movie clip's parent, and transform the movie clip and any of the clip's children.
The _focusrect, _highquality, _quality, and _soundbuftime properties are global; they belong only to the level 0 main timeline. All other properties belong to each movie clip or loaded level.
----------------

 

© 2008 by Jason C. Challas – www.jasonchallas.com