A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: Problem converting a AS2 script to a AS3

  1. #1
    Junior Member
    Join Date
    Nov 2008
    Posts
    21

    Question Problem converting a AS2 script to a AS3

    Hey all,

    I'm trying to convert a piece of code from AS2 to AS3. It's small piece of code. working with 1 symbol used 3 times and it makes/creates a parralax effect check it out at www.seniorict.com. Because I want to build the site in AS3 therefore I want to convert the code.
    But I'm finding a lot of errors can sombody help me to get it working?

    This is the old AS2 code

    Code:
    Stage.align = "TL";
    Stage.scaleMode = "NoScale";
    var root:MovieClip = this;
    var stageWidth:Number = Stage.width-1;
    var stageHeight:Number = Stage.height-1;
    var sizeOffset:Object = {x:(stageWidth-Stage.width)/2, y:(stageHeight-Stage.height)/2};
    var stageRatioX:Number = Stage.width;zzz
    var stageRatioY:Number = Stage.height;
    function generate(count:Number, minZ:Number, maxZ:Number, maxMove:Number, zEffect:Number, easeX:Number, easeY:Number):Void {
    	for (var i:Number = count; --i>-1; ) {
    		var base:MovieClip = root.iContainer ? iContainer : root.createEmptyMovieClip("iContainer", root.getNextHighestDepth());
    		var item:MovieClip = base.attachMovie("shape", "shape"+base.getNextHighestDepth(), base.getNextHighestDepth());
    		var newX:Number = Math.random()*stageWidth;
    		var newY:Number = Math.random()*stageHeight;
    		var newZ:Number = minZ+Math.random()*(maxZ-minZ);
    		item._alpha = item._xscale=item._yscale=newZ/maxZ*100;
    		item._rotation = Math.random()*360;
    		item.initX = item._x=newX-sizeOffset.x;
    		item.initY = item._y=newY-sizeOffset.y;
    		item._z = newZ;
    		item.maxMove = maxMove;
    		item.maxZ = maxZ;
    		item.minZ = minZ;
    		item.zEffect = zEffect;
    		item.easeX = easeX;
    		item.easeY = easeY;
    		item.swapDepths(newZ);
    		item.gotoAndStop(Math.ceil(Math.random()*item._totalframes));
    		item.onEnterFrame = moveItem;
    	}
    }
    function moveItem():Void {
    	this.tx = (this.initX+((((Stage.width/2-_xmouse)/(Stage.width/2)*this.maxMove)/this.maxMove*this._z)/(this.maxZ-this.minZ)*this.zEffect))*(Stage.width/stageRatioX);
    	this.ty = (this.initY+((((Stage.height/2-_ymouse)/(Stage.height/2)*this.maxMove)/this.maxMove*this._z)/(this.maxZ-this.minZ)*this.zEffect))*(Stage.height/stageRatioY);
    	this._x -= (this._x-this.tx)/this.easeX;
    	this._y -= (this._y-this.ty)/this.easeY;
    }
    generate(50, 50, 100, 30, 50, 15, 15);
    This is the new AS3 code
    Code:
    { 
    	stage.align = "TL";
    	import flash.display.MovieClip;
    	import flash.display.Stage;
    	Stage.scaleMode = "NoScale";
    	var root:MovieClip = this;
    	var stageWidth:Number = stage.stageWidth-1;
    	var stageHeight:Number = stage.stageHeight-1;
    	var sizeOffset:Object = {x:(stageWidth-stage.stageWidth)/2, y:(stageHeight-stage.stageHeight)/2};
    	var stageRatioX:Number = stage.stageWidth;zzz
    	var stageRatioY:Number = stage.stageHeight;
    	function generate(count:Number, minZ:Number, maxZ:Number, maxMove:Number, zEffect:Number, easeX:Number, easeY:Number):void {
    		for (public var i:Number = count; --i>-1; ) {
    			public var base:MovieClip = root.iContainer ? iContainer : root.createEmptyMovieClip("iContainer", root.getNextHighestDepth());
    			public var item:MovieClip = base.attachMovie("shape", "shape"+base.getNextHighestDepth(), base.getNextHighestDepth());
    			public var newX:Number = Math.random()*stageWidth;
    			public var newY:Number = Math.random()*stageHeight;
    			public var newZ:Number = minZ+Math.random()*(maxZ-minZ);
    			item.alpha = item.scaleX=item.scaleY=newZ/maxZ*100;
    			item.rotation = Math.random()*360;
    			item.initX = item.x=newX-sizeOffset.x;
    			item.initY = item.y=newY-sizeOffset.y;
    			item._z = newZ;
    			item.maxMove = maxMove;
    			item.maxZ = maxZ;
    			item.minZ = minZ;
    			item.zEffect = zEffect;
    			item.easeX = easeX;
    			item.easeY = easeY;
    			item.swapDepths(newZ);
    			item.gotoAndStop(Math.ceil(Math.random()*item.totalFrames));
    			item.onEnterFrame = moveItem;
    		}
    	}
    	function moveItem():void {
    		this.tx = (this.initX+((((stage.stageWidth/2-mouseX)/(stage.stageWidth/2)*this.maxMove)/this.maxMove*this._z)/(this.maxZ-this.minZ)*this.zEffect))*(stage.stageWidth/stageRatioX);
    		this.ty = (this.initY+((((stage.stageHeight/2-mouseY)/(stage.stageHeight/2)*this.maxMove)/this.maxMove*this._z)/(this.maxZ-this.minZ)*this.zEffect))*(stage.stageHeight/stageRatioY);
    		this.x -= (this.x-this.tx)/this.easeX;
    		this.y -= (this.y-this.ty)/this.easeY;
    	}
    	generate(50, 50, 100, 30, 50, 15, 15);
    }
    Thanks in advance!
    Last edited by chrisdegrote; 07-12-2009 at 06:26 PM. Reason: not complete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center