A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: [RESOLVED] Does this seem to have any deprecated code or alike?

  1. #1
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389

    resolved [RESOLVED] Does this seem to have any deprecated code or alike?

    Hi, the code I'm pasting is AS1 code from an old example of a character icon moving to all directions and I'm trying to code it in AS2 to be able to use in my experiment. The code below is my version in AS2 where it will work halfway. The character will not turn towards the top of the screen. I wonder whether there is some deprecated method in it that won't let it work properly in AS2 but I couldn't find out.



    Code:
    function initializeCharacter(name) {
    	path = people[name];
    	path.speed = 5;
    	path.locked = false;
    	path.angleSpan = 360/8;
    	path.clip.ob = path;
    	path.clip.move = move;
    	if (name == ElectroServer.username) {
    		path.myCharacter = true;
    		path.clip.onMouseMove = mouseMoved;
    		path.clip.onMouseDown = mouseGotClicked;
    	}
    }
    
    function move(endX, endY, angle, number) {
    	//Store the information passed in
    	this.ob.endX = endX;
    	this.ob.endY = endY;
    	this.ob.angle = angle;
    	this.ob.number = number;
    	//Calculate the x and y speed at which to walk
    	this.ob.xmov = this.ob.speed*Math.cos(this.ob.angle);
    	this.ob.ymov = this.ob.speed*Math.sin(this.ob.angle);
    	//Create variables that store your starting position
    	this.ob.startX = this.ob.x;
    	this.ob.startY = this.ob.y;
    	//Send the character to the correct walking frame
    	this.character.gotoAndStop("walk_"+number);
    	//Lock it so there can be no input
    	this.ob.locked = true;
    	//Create an onEnterFrame event to move the character
    	this.onEnterFrame = function() {
    		//Update the position
    		this.ob.x += this.ob.xmov;
    		this.ob.y += this.ob.ymov;
    		this._x = this.ob.x;
    		this._y = this.ob.y;
    		//Check to see if the character has arrived at the destination
    		if ((this.ob.endX-this.ob.startX)/Math.abs(this.ob.endX-this.ob.startX) != (this.ob.endX-this.ob.x)/Math.abs(this.ob.endX-this.ob.x) || (this.ob.endY-this.ob.startY)/Math.abs(this.ob.endY-this.ob.startY) != (this.ob.endY-this.ob.y)/Math.abs(this.ob.endY-this.ob.y)) {
    			this.ob.x = this.ob.endX;
    			this.ob.y = this.ob.endY;
    			this._x = this.ob.x;
    			this._y = this.ob.y;
    			this.character.gotoAndStop("stand_"+this.ob.number);
    			//Unlock the character if it is yours
    			if (this.ob.myCharacter) {
    				this.ob.locked = false;
    				this.mouseMoved();
    			}
    			this.onEnterFrame = null;
    		}
    	};
    }
    
    function mouseGotClicked() {
    	if (!this.ob.locked && !_root.chat.offlimits.hitTest(_root._xmouse, _root._ymouse)) {
    		this.lastClicked = this.now;
    		this.now = getTimer();
    		if (this.now-this.lastClicked<500) {
    			var mx = this._parent._xmouse;
    			var my = this._parent._ymouse;
    			if (this.ob.endX != mx && this.ob.endY != my) {
    				this.ob.endX = mx;
    				this.ob.endY = my;
    				_root.moveMe();
    			}
    		}
    	}
    }
    
    function mouseMoved() {
    	updateAfterEvent();
    	if (!this.ob.locked) {
    		var mx = this._parent._xmouse;
    		var my = this._parent._ymouse;
    		var xDiff = mx-this._x;
    		var yDiff = my-this._y;
    		var angle = Math.atan2(yDiff, xDiff);
    		var realAngle = angle*180/Math.PI;
    		if (realAngle<0) {
    			var realAngle = realangle+360;
    		}
    		var number = Math.ceil(realAngle/this.ob.angleSpan);
    		this.character.gotoAndStop("stand_"+number);
    		this.ob.angle = angle;
    		this.ob.number = number;
    	}
    }
    
     ----------------------------------------------------------------------------------------
    
    function initializeCharacter(name:Object):Void {
    	path = people[name];
    	path.speed = 5;
    	path.locked = false;
    	path.angleSpan = 360/8;
    	path.clip.ob = path;
    	path.clip.move = move;
    	if (name == server.username) {
    		path.myCharacter = true;
    		path.clip.onMouseMove = mouseMoved;
    		path.clip.onMouseDown = mouseGotClicked;
    	}
    }
    
    function move(endX:Number, endY:Number, angle:Number, number:Number):Void {
    	//Store the information passed in
    	this.ob.endX = endX;
    	this.ob.endY = endY;
    	this.ob.angle = angle;
    	this.ob.number = number;
    	//Calculate the x and y speed at which to walk
    	this.ob.xmov = this.ob.speed*Math.cos(this.ob.angle);
    	this.ob.ymov = this.ob.speed*Math.sin(this.ob.angle);
    	//Create variables that store your starting position
    	this.ob.startX = this.ob.x;
    	this.ob.startY = this.ob.y;
    	//Send the character to the correct walking frame
    	this.character.gotoAndStop("walk_"+number);
    	//Lock it so there can be no input
    	this.ob.locked = true;
    	//Create an onEnterFrame event to move the character
    	this.onEnterFrame = function() {
    		//Update the position
    		this.ob.x += this.ob.xmov;
    		this.ob.y += this.ob.ymov;
    		this._x = this.ob.x;
    		this._y = this.ob.y;
    		//Check to see if the character has arrived at the destination
    		if ((this.ob.endX-this.ob.startX)/Math.abs(this.ob.endX-this.ob.startX) != (this.ob.endX-this.ob.x)/Math.abs(this.ob.endX-this.ob.x) || (this.ob.endY-this.ob.startY)/Math.abs(this.ob.endY-this.ob.startY) != (this.ob.endY-this.ob.y)/Math.abs(this.ob.endY-this.ob.y)) {
    			this.ob.x = this.ob.endX;
    			this.ob.y = this.ob.endY;
    			this._x = this.ob.x;
    			this._y = this.ob.y;
    			this.character.gotoAndStop("stand_"+this.ob.number);
    			//Unlock the character if it is yours
    			if (this.ob.myCharacter) {
    				this.ob.locked = false;
    				this.mouseMoved();
    			}
    			this.onEnterFrame = null;
    		}
    	};
    }
    
    function mouseGotClicked():Void {
    	if (!this.ob.locked && !_root.board.offlimits.hitTest(_root._xmouse, _root._ymouse)) {
    		this.lastClicked = this.now;
    		this.now = getTimer();
    		if (this.now-this.lastClicked<500) {
    			var MX = this._parent._xmouse;
    			var MY = this._parent._ymouse;
    			if (this.ob.endX != MX && this.ob.endY != MY) {
    				this.ob.endX = MX;
    				this.ob.endY = MY;
    				_root.moveMe();
    			}
    		}
    	}
    }
    
    function mouseMoved():Void {
    	updateAfterEvent();
    	if (!this.ob.locked) {
    		var MX = this._parent._xmouse;
    		var MY = this._parent._ymouse;
    		var xDiff = MX-this._x;
    		var yDiff = MY-this._y;
    		var angle = Math.atan2(yDiff, xDiff);
    		var realAngle = angle*180/Math.PI;
    		if (realAngle<0) {
    			var realAngle = realangle+360;
    		}
    		var number = Math.ceil(realAngle/this.ob.angleSpan);
    		this.character.gotoAndStop("stand_"+number);
    		this.ob.angle = angle;
    		this.ob.number = number;
    	}
    }

  2. #2
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    Sorry for posting all that code. I bet it has to be something related to the angle.

  3. #3
    Senior Member
    Join Date
    Jan 2007
    Location
    Barcelona
    Posts
    389
    I don't know why, but maybe it was the reserved name. This code does work:

    Code:
    function initializeCharacter(myName) {
    	path = people[myName];
    	path.speed = 5;
    	path.angleSpan = 360/8;
    	path.locked = false;
    	path.clip.ob = path;
    	path.clip.move = move;
    	if (myName == username) {
    		path.myCharacter = true;
    		path.clip.onMouseMove = mouseMoved;
    		path.clip.onMouseDown = mouseGotClicked;
    	}
    }
    function move(endX, endY, angle, myNumber) {
    	// Store the information passed in
    	this.ob.endX = endX;
    	this.ob.endY = endY;
    	this.ob.angle = angle;
    	this.ob.myNumber = myNumber;
    	// Calculate the x and y speed at which to walk
    	this.ob.xmov = this.ob.speed*Math.cos(this.ob.angle);
    	this.ob.ymov = this.ob.speed*Math.sin(this.ob.angle);
    	// Create variables that store your starting position
    	this.ob.startX = this.ob.x;
    	this.ob.startY = this.ob.y;
    	// Send the character to the correct walking frame
    	this.character.gotoAndStop("walk_"+myNumber);
    	// Lock it so there can be no input
    	this.ob.locked = true;
    	// Create an onEnterFrame event to move the character
    	this.onEnterFrame = function() {
    		// Update the position
    		this.ob.x += this.ob.xmov;
    		this.ob.y += this.ob.ymov;
    		this._x = this.ob.x;
    		this._y = this.ob.y;
    		// Check to see if the character has arrived at the destination
    		if ((this.ob.endX-this.ob.startX)/Math.abs(this.ob.endX-this.ob.startX) != (this.ob.endX-this.ob.x)/Math.abs(this.ob.endX-this.ob.x) || (this.ob.endY-this.ob.startY)/Math.abs(this.ob.endY-this.ob.startY) != (this.ob.endY-this.ob.y)/Math.abs(this.ob.endY-this.ob.y)) {
    			this.ob.x = this.ob.endX;
    			this.ob.y = this.ob.endY;
    			this._x = this.ob.x;
    			this._y = this.ob.y;
    			this.character.gotoAndStop("stand_"+this.ob.myNumber);
    			// Unlock the character if it is yours
    			if (this.ob.myCharacter) {
    				this.ob.locked = false;
    				this.mouseMoved();
    			}
    			this.onEnterFrame = null;
    		}
    	};
    }
    function mouseGotClicked() {
    	if (!this.ob.locked && !_root.chat.offlimits.hitTest(_root._xmouse, _root._ymouse)) {
    		this.lastClicked = this.now;
    		this.now = getTimer();
    		//fa desaparèixer el ninot al primer clic
    		//path.clip._visible = false;
    		if (this.now-this.lastClicked<500) {
    			var mx = this._parent._xmouse;
    			var my = this._parent._ymouse;
    			if (this.ob.endX != mx && this.ob.endY != my) {
    				this.ob.endX = mx;
    				this.ob.endY = my;
    				_root.moveMe();
    			}
    		}
    	}
    }
    function mouseMoved() {
    	updateAfterEvent();
    	if (!this.ob.locked) {
    		var mx = this._parent._xmouse;
    		var my = this._parent._ymouse;
    		var xDiff = mx-this._x;
    		var yDiff = my-this._y;
    		var angle = Math.atan2(yDiff, xDiff);
    		var realAngle = angle*180/Math.PI;
    		if (realAngle<0) {
    			var realAngle = realAngle+360;
    		}
    		var myNumber = Math.ceil(realAngle/this.ob.angleSpan);
    		this.character.gotoAndStop("stand_"+myNumber);
    		this.ob.angle = angle;
    		this.ob.myNumber = myNumber;
    	}
    }

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