Here is a another Fuse example of moving a clip around the stage to a new random point every time you click on it. A simple illustration of what Fuse can do.
[kml_flashembed movie=”/wp-content/uploads/fuse/Button-Random-Tween.swf” width=”700″ height=”300″ /]
And here is the code for the above example.
[as]
/*****************************************************************************
=============================================================================
EXAMPLE FILE:
Make a button that moves randomly about the stage when you click on it.
=============================================================================
EXAMPLE CREDIT:
Ryan Potter
www.ThoughtWillRise.com
License: Same as Fuse.
=============================================================================
FUSE CREDIT:
Fuse Kit 2
Copyright (c) 2006 Moses Gunesch, MosesSupposes.com
Distributed under MIT Open Source License, see Fuse-Kit-License.html (in fuse package directory)
Easing Equations (c) 2003 Robert Penner used by permission, see PennerEasing
Visit http://www.mosessupposes.com/Fuse
=============================================================================
EXPLANATION:
Load in the Fuse and Delegate Classes.
Register FuseItem for object syntax and Penner’s easing equations.
Draw a box on the stage.
Create a press handler that delegates to a move box function.
This makes it so when you press on the box it moves to a new random spot.
=============================================================================
*****************************************************************************/
// IMPORT THE CLASSES
import com.mosesSupposes.fuse.*;
import mx.utils.Delegate;
init(); // Start things going
function init(){
ZigoEngine.register(FuseItem, PennerEasing);
this.box = this.drawClip(this, “box”, this.getNextHighestDepth(), 50, 50, 0xFFCC00);
this.box._x = 250;
this.box._y = 100;
this.box.onPress = Delegate.create(this, moveBox);
this.drawLabel(this, “Click the box to see the tween”, 20, 20);
}
function moveBox(){
ZigoEngine.removeTween(this.box);
ZigoEngine.doTween({target:this.box, x:this.getRandX(), y:this.getRandY(), ease:”easeOutExpo”, seconds:2});
}
function drawClip(target, clip, depth, w, h, color){
var c = target.createEmptyMovieClip(clip+depth, depth);
c.beginFill(color, 100);
c.moveTo(0,0);
c.lineTo(w,0);
c.lineTo(w,h);
c.lineTo(0,h);
c.lineTo(0,0);
c.endFill();
return c;
}
function drawLabel(target, text, x, y){
target.createTextField(”tf”, target.getNextHighestDepth(), x, y, 10, 10 );
target.tf.autoSize = true;
target.tf.multiline = false;
target.tf.wordWrap = false;
target.tf.text = text;
var my_fmt:TextFormat = new TextFormat();
my_fmt.bold = true;
my_fmt.color = 0xffffff;
my_fmt.font = “_sans”;
target.tf.setTextFormat(my_fmt);
}
function getRandX(){
var r:Number=50+Math.floor(Math.random()*(Stage.width-150));
return r;
}
function getRandY(){
var r:Number=50+Math.floor(Math.random()*(Stage.height-150));
return r;
}
[/as]
Post a Comment