Thursday, May 24, 2007

Project 8: Drag and drop a movie clip



The basic setup was simple. Created a movie clip with a button inside, then created a drop target and called the instance 'puddle'.

The code for the button inside the movie clip was:

on (press) {
startDrag (this, true);
}
on (release) {
stopDrag ();
if (this._droptarget == "/puddle") {
_root.bat._visible = false;

_root.puddle.gotoAndStop(2);
}
}


However, in order to get an animation of the splash in the water, the character dripping, and the 'bring him back' button to pop up at specific times, I made use of actionscript on keyframes in specific areas of movie clips and buttons. The whole thing was actually pretty tangled for such a simple project and would be better handled with globals in the future.

Tuesday, May 22, 2007

Project 7: Bouncy Ball



The code for the gravity came from an excellent tutorial on flash physics. Google 'flash gravity effect' and it's the first to show. The code for the shadow is my doing >_<

The Code (attached to the shadow movie clip):

onClipEvent(load) {
var mcheight:Number = this._height;
var mcwidth:Number = this._width;
}
onClipEvent(enterFrame) {
_root.shadow2._x = _root.ball._x;
var difference:Number = this._y - _root.ball._y;
this._height = (difference/20) + 15;
this._width = (difference/20) + 55;
this._alpha = (100 - (difference/2)) + 90;
}

Project 6: eyes following the cursor



This code came from a tutorial and involved the use of trigonometry and flash's tan function. All frames containing the code and the movie clips were put into a single movie clip, so that there could be three instances of the eyeball watching critter on the stage.

The Code:

a = eye._y-_ymouse;
b = eye._x-_xmouse;
angleA = Math.atan2(a, b);
degrees = angleA/(Math.pi/180);
setProperty ("eye", _rotation, degrees);
setProperty ("eye2", _rotation, degrees);

Monday, May 21, 2007

Project 5: Rollover object



This project required very little actionscript. The object is a button with various movie clips for the rollover states. Movie clips include scripting at certain frames to instruct the clips to loop only at certain points. So for instance when the character goes to the sleeping state, he only drifts off once so that it's the snoring that loops rather than the whole thing.

Project 4: Simple Cursor Trail



The fading effect is accomplished by creating a fade to 0% shape tween inside the movie clip 'aniGuy'.

The Code:

depth = 0;
attachMovie("aniGuy","guy",depth++);
guy = _root["guy"];
guy._alpha = 0;
mouseListener = new Object();
Mouse.addListener(mouseListener);

this.onEnterFrame = function()
{
_root["guy"+depth].removeMovieClip();
_root.guy.duplicateMovieClip("guy"+depth,depth);

thisGuy = _root["guy"+depth];
thisGuy._x = _root._xmouse;
thisGuy._y = _root._ymouse;
thisGuy._alpha = 100;
depth++;
if ( depth > 10 )
{
depth = 1;
}
}


VARIATION: For a simple variation I added a line of code to tell the dragged movie clip to go to and stop on a specific frame. In this case I attached the frame number to the depth for ease.




The Code Bit:
...
thisGuy = _root["guy"+depth];
thisGuy.gotoAndStop(depth);
thisGuy._x = _root._xmouse;
thisGuy._y = _root._ymouse;
thisGuy._alpha = 100;
...

Friday, May 18, 2007

Project 3: Move and rotate movie clip with buttons



For this I took and then modified some code found from the internets. In this file, all code was put into a single actions layer rather than attached to each individual button.

The code:

moveUp.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y -= 4;
}
}
moveUp.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

moveDown.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y += 4;
}
}
moveDown.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

moveLeft.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._x -= 4;
}
}
moveLeft.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

moveRight.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._x += 4;
}
}
moveRight.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}


rotateRight.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._rotation += 3;
}
}

rotateRight.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy._rotation = mcGuy2._rotation;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

rotateLeft.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._rotation -= 3;
}
}

rotateLeft.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy._rotation = mcGuy2._rotation;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}




moveUpLeft.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y -= 4;
this._x -= 4;
}
}
moveUpLeft.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}



moveUpRight.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y -= 4;
this._x += 4;
}
}
moveUpRight.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}


moveDownRight.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y += 4;
this._x += 4;
}
}
moveDownRight.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

moveDownLeft.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y += 4;
this._x -= 4;
}
}
moveDownLeft.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

Reset.onPress = function() {
mcGuy2.onEnterFrame = function() {
mcGuy2._alpha = 100;
mcGuy._alpha = 0;
this._y = 150;
this._x = 180;
this._rotation = 0;
}
}
Reset.onRelease = function() {
mcGuy._x = mcGuy2._x;
mcGuy._y = mcGuy2._y;
mcGuy._rotation = mcGuy2._rotation;
mcGuy2._alpha = 0;
mcGuy._alpha = 100;
delete mcGuy2.onEnterFrame;
}

Project 2: controlling a movie clip with a button



Very simple to code. I created two buttons, and a movie clip instance named 'mcPlay'. Code:

(Button to stop animation)

on (release) {
_root.mcPlay.stop();
}


(Button to resume animation)

on (release) {
_root.mcPlay.play();
}

Thursday, May 17, 2007

Project 1: Swap the cursor with buttons



Until I find a way to get embedded .swfs to show up in blogger, these projects will have to be links. >_<

In this project I created three different cursors with three different buttons, each of which is programmed to swap out the cursor which the user is controlling.