Hey Andy.
You might want to try adding an event listener for the ENTER_FRAME event and set up a handler function to update the text box each time the event is detected.
The ENTER_FRAME event is an event which is dispatched by Flash's event dispatcher each time a new frame is drawn. So by adding an event listener and a handler, you can update the text box each time a new frame is drawn.
Here's a simple, yet complete example of what I mean (Note: This is done in AS3/Flex not the Flash IDE...I've not used the Flash IDE for years!):
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.text.TextField;
/**
* Example using Flex SDK.
* Creates two text fields.
* Uses an event listener and a handler function to update the text-boxes
* with the X and Y positions of the mouse cursor.
*/
[SWF(backgroundColor="0xffffff", width="800", height="600", frameRate="25")]
public class UpdateText extends Sprite
{
private var text1:TextField;
private var text2:TextField;
public function UpdateText()
{
// Add two text fields to the stage.
text1 = new TextField;
addChild(text1);
text2 = new TextField;
text2.y = 20; // place text2 directly underneath text1
addChild(text2);
// Set up an event listener to listen for the ENTER_FRAME event.
this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
// This is the function we specified in our event listener.
// This will deal with updating the text boxes each time the listener
// detects an ENTER_FRAME event
private function onEnterFrame(e:Event):void
{
text1.text = "Mouse X = " + String(mouseX);
text2.text = "Mouse Y = " + String(mouseY);
}
}
}
The above example creates two text boxes and sets up an event listener and an associated handler function for the ENTER_FRAME event. Each time ENTER_FRAME is detected, the listener calls the handler function (onEnterFrame), which updates the two text boxes with the current X and Y positions of the mouse cursor.
OK, so I'm using the mouse co-ords, but it works exactly the same way for any other objects properties!
However, the above example is targetted towards using the Flex SDK rather than the Flash IDE. But it's still AS3, so the principles behind it still apply in the IDE.
So assuming you're using the Flash IDE; for your purposes, wherever you've currently got your actionscript for setting the text for xCo_txt, you'll probably need to add something like this:
function onEnterFrame(e:event):void
{
xCo_txt.text = String(box.x);
}
this.addEventListenter(Event.ENTER_FRAME, onEnterFrame);
That might do the trick... It might not be exactly right, but as I said I've not used the flash IDE for a loooong time. Either way you almost certainly need to add an event listener and a handler function IMHO!
JasonHippy
Practically a Posting Shark
862 posts since Jan 2009
Reputation Points: 615
Solved Threads: 146
Skill Endorsements: 5
No worries, glad to have helped!
JasonHippy
Practically a Posting Shark
862 posts since Jan 2009
Reputation Points: 615
Solved Threads: 146
Skill Endorsements: 5