dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Displyaing my return value query

  1. #1
    Senior Member
    Join Date
    May 2007
    Posts
    102

    Displyaing my return value query

    Hi,

    i have made a very simple application where i have created a ball which follows the mouse. However, seeing that i am new to this, what is the easiest/common way for me to be able to display the value of my "distance" variable without having to make my velFriction of type void? because if i make it void i can trace the distance value between the ball and the mouse but the ball moviclip stays still.

    Code:
    package  
    {
    	
    	/**
    	 * Zenos.as is meant to show how you can demonstrate friction using the Zenos Paradox theory
    	 * @author Luong Vuong
    	 * Date created: 21/12/2009
    	 * Last modified: 21/12/2009
    	 */
    	
    	import flash.display.MovieClip;
    	import flash.display.Sprite;
    	import flash.events.Event;
    	
    	public class Zenos extends Sprite 
    	{
    		private var ball:MovieClip;
    		
    		public function Zenos() :void 
    		{
    			ball = new Ball();
    			ball.x = ball.y = 100;
    			 
    			construct();
    			
    			 
    		}
    		
    			 
    		// Add listeners and add UI to display list
    		public function construct() :void
    		{
    			addChild(ball);
    			addEventListener(Event.ENTER_FRAME, onLoop, false, 0, true);
    				 
    			 
    
    		}
    		
    		public function onLoop(evt:Event) :void
    		{
    			ball.x += velFriction(ball.x, mouseX, 5);
    			ball.y += velFriction(ball.y, mouseY, 5);
    		}
    		
    		
    		public function velFriction(orig:Number, dest:Number, coef:Number) :Number
    		{ 	
    			var distance:Number = (dest - orig) / coef;
    
    			  return distance ;
    			 
    			
    		}
    	}
     
    }
    Thanks
    This is taken from Learning Actionscript:A Beginners Guide pg. 128
    Last edited by nvidia123; 12-21-2009 at 06:33 PM.

  2. #2
    rabid_Delineator AttackRabbit's Avatar
    Join Date
    Dec 2003
    Location
    Orlando, Florida
    Posts
    481
    you can trace within a function thats returns a value or object.just make sure you put your trace statements before the
    Code:
    return;
    .

  3. #3
    Senior Member
    Join Date
    May 2007
    Posts
    102
    Quote Originally Posted by AttackRabbit View Post
    you can trace within a function thats returns a value or object.just make sure you put your trace statements before the
    Code:
    return;
    .
    Aah i see, because i did something like this but after the return value, i thought that i would not make any difference as to where i place the trace statement, either before or after but clearly it does. Thanks

  4. #4
    Senior Member
    Join Date
    Jul 2006
    Location
    San Jose, CA
    Posts
    334
    Quote Originally Posted by nvidia123 View Post
    Aah i see, because i did something like this but after the return value, i thought that i would not make any difference as to where i place the trace statement, either before or after but clearly it does. Thanks
    'return' exits the function. AS3 is read top left to bottom right, in that order. So yes, placement matters.
    I (Love | Hate) Flash.
    ----
    Save a version back so others may help you!

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