A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: dynamic text and speed

  1. #1
    Junior Member
    Join Date
    Jun 2002
    Posts
    4
    I have an object that I move with the arrow keys. If you open up movement-thrust.fla example in program files\macromedia\flash mx\samples\fla you will see what I am working with. If you replace the current action script for the bug with this:
    Code:
    onClipEvent (load) {
    	// declare and set initial variables
    	thrust = 1;
    	decay = 1;
    	maxSpeed = 5;
    	xthrust = 1;
    	flames._visible = 0;
    	ySpeed = -1;
    	xSpeed = -1;
    }
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.RIGHT)) {
    		//Move right
    		xSpeed += xthrust;
    		flames._visible = 0;
    	}
    	if (Key.isDown(Key.LEFT)) {
    		// move left
    		xSpeed -= xthrust;
    		flames._visible = 0;
    	}
    	// 
    	if (Key.isDown(Key.UP)) {
    		//move up
    		ySpeed += thrust;
    	}
    	if (Key.isDown(Key.DOWN)) {
    		//move down
    		ySpeed -= thrust;
    	}
    	// maintain speed limit
    	speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
    	if (speed>maxSpeed) {
    		xSpeed *= maxSpeed/speed;
    		ySpeed *= maxSpeed/speed;
    	}
    	// 
    	// move beetle based on calculations above
    	_y -= ySpeed;
    	_x += xSpeed;
    	// 
    	// Keep the bug from moving off screen. 
    	if (_y<0) {
    		_y = 0;
    	}
    	if (_y>232) {
    		_y = 232;
    	}
    	if (_x<0) {
    		_x = 0;
    	}
    	if (_x>465) {
    		_x = 465;
    	}
    }
    You will see what I am working with.

    Eventually I want to apply this script to the hot air balloon in this picture:



    My problem is that I would like to somehow output a correlation between the xSpeed, ySpeed, and the various forces. I would like to do this using dynamic text. For example, when the ySpeed=2, I would like the gravity to be 20,000 and the air pressure to be 40,000.

    Does anyone have any ideas on how I can do this?

    Thanks.
    Brian

  2. #2
    Junior Member
    Join Date
    Jul 2002
    Posts
    25
    You could just assign variables to dynamic text fields.

    Try this:
    Code:
    // Create some text fields to display your variables
    _root.createTextField("tfGravity", 1, 10, 10, 40, 20);
    tfGravity.autoSize = true;
    tfGravity.variable = "gravity";
    _root.createTextField("tfAirPressure", 2, 10, 30, 40, 20);
    tfAirPressure.autoSize = true;
    tfAirPressure.variable = "airPressure";
    
    // You can put this pretty much anywhere
    // Also, I don't know what kind of calculations you're doing, so I
    // just put these types of calculations in.
    gravity = ySpeed*10000;
    airPressure = 2*gravity;
    I hope this helps.

    L8r.

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