« Me on Flash Remoting @ FMUG.az meeting | ^ Main | Simple DOA with Base class »


Resizing Interface

A user group member asked how http://www.skyloftsmgmgrand.com/ was built so we, on the list, started discussing it briefly. In an attempt to help the member understand a little better I did an example file. It doesn’t do much but keep resizing/repositioning the background (bg) clip and make two other clips (representations of the logo and navigation for the example site) move accordingly.

Initially I did one that simply resized the bg and had the clips follow then followed it up with the code to use tweening instead. Both are super short in terms of code but get the job done.

You can download the files in the Resources -> Code Library section of FMUG.az’s site.

bc[as]..
//site.as without tweening
//This is the _root of the movie
var bg:MovieClip;
var logo:MovieClip;
var nav:MovieClip;
var change_interval:Number;

function changeSize(clip:MovieClip, xscale:Number, yscale:Number, x:Number, y:Number){
clip._xscale = xscale;
clip._yscale = yscale;
clip._x = x;
clip._y = y;

logo._x = x + 10;
logo._y = y + 10;

nav._x = x + 10;
nav._y = y + 100;
}

change_interval = setInterval(this, “changeSize”, 2500, bg, 90, 80, 100, 100);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//site.as with tweening
//This is the _root of the movie

import mx.transitions.Tween;

var bg:MovieClip;
var logo:MovieClip;
var nav:MovieClip;

var duration:Number = 10;
var change_interval:Number;

function changeSize(clip:MovieClip, xscale:Number, yscale:Number, x:Number, y:Number){
clearInterval(change_interval);
var b:Tween = new Tween(clip, “_xscale”, mx.transitions.easing.Strong.easeIn, clip._xscale, xscale, duration, false)
var b:Tween = new Tween(clip, “_yscale”, mx.transitions.easing.Strong.easeIn, clip._yscale, yscale, duration, false)
var x_tween:Tween = new Tween(clip, “_x”, mx.transitions.easing.Strong.easeIn, clip._x, x, duration, false)
var y_tween:Tween = new Tween(clip, “_y”, mx.transitions.easing.Strong.easeIn, clip._y, y, duration, false)

x_tween.onMotionChanged = function(){
logo._x = this.position + 10;
nav._x = this.position + 10;
}

y_tween.onMotionChanged = function(){
logo._y = this.position + 10;
nav._y = this.position + 100;
}

x_tween.onMotionFinished = function(){
go();
}
}

function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNum;
}

function go(){
clearInterval(change_interval);
changeSize(bg, randRange(50, 100), randRange(50, 100), randRange(0, Stage.width/2), randRange(0, Stage.height/2));
}

change_interval = setInterval(this, “go”, 300);

Posted by John C. Bland II on January 22, 2006 1:09 AM |

TrackBack

TrackBack URL for this entry:
http://mt.katapultmedia.com/mt-tb.cgi/8

Comments


gzywhd vzoxutdh yvkbus htdkm wbnzkpde mjzq qzsbxf

Posted by: qucgwj qtdpk | August 23, 2007 8:32 PM


gzywhd vzoxutdh yvkbus htdkm wbnzkpde mjzq qzsbxf

Posted by: qucgwj qtdpk | August 23, 2007 8:33 PM

Post a comment