PDA

View Full Version : Image Swap Script


irukandji
09-21-2007, 11:29 AM
I've been working with Flash for several months and seem to grasp all the animation techniques of motion and shape tween, drawing etc.. but when it come to AS I am lost lost lost.
I want to start simple by making mouse overs for images using AS alone.
I have two images, one B&W the other Color. When my page loads the b&w one displays, but when moused over I want it to swap the image to a color one.
How do I do this simple image swap using only AS?

Headshotz
09-21-2007, 11:43 AM
Say your colour image is called "i1" and your black and white is "i2"; this code is really simple, just makes sure the colour one is over the top of the B&W but only visible if the mouse is over it.


i1.swapDepths(10000)
i2.swapDepths(9999)
i1._alpha = 0;
i1.onRollOver = function() {
i1._alpha = 100;
}
i1.onRollOut = function() {
i1._alpha = 0;
}

irukandji
09-21-2007, 02:25 PM
Great! I now have an image rollover swap that works!

Lucidity
10-17-2007, 09:23 PM
instead of alpha, I'd use:
i1._visibility = true; & i1._visibility = false;

With alpha, the object is still clickable, if you were to have an onRelease or onMouseDown function attached. With visibility, it is not clickable. May not matter in this case, but just an altenative.