Tweener class
Here a couple of basic scripts for the tweener class..
On frame tween:
import caurina.transitions.*;
Tweener.addTween(_root.myMovieClip, {_x:100, _y:100, transition:"easeOutQuad", time:1});
/* set the X and Y values to where you want the destination of your tween */
/* set the time in seconds */
on button tween:
import caurina.transitions.*;
var newPosX:Number;
var newPosY:Number;
ButtonOne.onRelease = function() {
newPosX = 100;
newPosY = 100;
moveMC();
};
ButtonTwo.onRelease = function() {
newPosX = 200;
newPosY = 200;
moveMC();
};
moveMC = function() {
Tweener.addTween(BG_MC, {_x:newPosX, _y:newPosY, transition:"easeOutQuad", time:2});
}
setTimeout – Creating a pause in the script.
So I had a bunch of actions, that I want to be executed after a small delay..
In this example, I have a button that will do 2 things: create a tween on a movieclip, and then (after a small 1 second delay) move to a specified place on the time line. Here’s how to do it:
** please note: I’ve used the TWEENER class to create the tween **
myButton.onRelease = function() {
import caurina.transitions.*;
Tweener.addTween(_root.site.myMovieClip, {_x:0, _y:0, transition:"easeOutQuad", time:1});
setTimeout(testTimeOut,1000);
};
function testTimeOut(){
_root.site.gotoAndPlay("home");
};
Here is how it works:
myButton.onRelease = function() {
/* INSERT FIRST ACTION TO BE PERFORMED HERE */
setTimeout(testTimeOut,1000); /* THIS CREATES A FUNCTION CALLED setTimeout. 1000 = 1 second */
};
/* THE FOLLOWING LINE CALLS THE FUNCTION */
function testTimeOut(){
/* INSERT SECOND ACTION TO BE PERFORMED AFTER THE DELAY HERE */
};
Tweening & Scaling a Movieclip from a button
So I have movie clip that contains an image, and want to move (tween) and change the dimensions (scale) the movieclip when I press a button..
My button instance name is: BTN1 – Note that this needs to beĀ a movieclip (not a button at all)
My Movieclip instance name is: myMovieClip – and in this case is actually on the root timeline
Here’s how:
import mx.transitions.Tween;
import mx.transitions.easing.*;
BTN1.onPress = function(){
new Tween(_root.myMovieClip,”_x”,Strong.easeOut,_root.myMovieClip._x, 40,2,true);//2 is the num of seconds
new Tween(_root.myMovieClip,”_y”,Strong.easeOut,_root.myMovieClip._y, 100,2,true);
new Tween(_root.myMovieClip,”_width”,Strong.easeOut,_root.myMovieClip._width,600,2,true);
new Tween(_root.myMovieClip,”_height”,Strong.easeOut,_root.myMovieClip._height,600,2,true);
}
Button Link To Another Movieclip
A little tip for those getting aquainted with Actionscript.
So I have a button inside a movieclip called MC1. I need this button to link to a label called HOME on a totally different movieclip called MC2. Here’s the code that should be placed on a seperate layer to the button:
button_name.onRelease=function(){
_root.MC2.gotoAndPlay(“home”);
}
Or, alternately you could place the following script directly on the button (Not on a seperate layer):
on(release){
_root.MC2.gotoAndPlay(“home”);
}
In the case that MC1 was inside MC2 rather than being completely seperate, you could use parent:
on(release){
_parent.gotoAndPlay(“home”);
}
External SWF With Dynamic Content – Green Border Fix
I found that when trying to load an external SWF that contained dynamic content into a movieclip, an unwanted green border was appearing around the external SWF when testing it in my browser. Here’s the fix:
- Create an ampty movieclip with the instance name STAGE
- Add a behaviour to load external movie clip onto the STAGE
- Add the following actionscript (AS2) on a seperate layer:
stage._lockout=true; /* gets rid of the green border bug */
stage.loadMovie(“external_swf.swf”);

leave a comment