Jump to content


Coded Rotation of TextInput in Flex3

Recommended Posts

I am having trouble rotating a TextInput type in Flex using the FlexTransformManager.


I get the following, when trying to rotate an item in code:


"TypeError: Error #1009: Cannot access a property or method of a null object reference."


protected function reposition():void { //Ensures that the _origin lines up with the _localOrigin.

----->>> var p:Point = _target.parent.globalToLocal(_target.localToGlobal(_localOrigin));

the _target.parent - is null!



------ CODE --------------------------

var MyNewSWF:TextInput = new TextInput();
MyNewSWF.id = IdName;
MyNewSWF.text = sText;
//--- add item to transform Manager ----
myManager.addItem(MyNewSWF, "SCALE_WIDTH_AND_HEIGHT",true);
//--- select the item ----

//--- move selection works!!! -------





Is there another way to rotate an item? A work around?




Link to comment
Share on other sites

Two questions:


1) Are you using the latest version (1.66 or later)


2) Does trace(MyNewSWF.parent) return null if you put it right before the addItem()?

Link to comment
Share on other sites

1. I am using the following Versions I got from your site a few weeks ago.


VERSION: 1.65 --DATE: 3/27/2009 -- TransformManger.as

VERSION: 1.61 --DATE: 3/25/2009 -- FlexTransformManager.as

VERSION: 1.6 -- DATE: 3/12/2009 -- TransformManager.as


2. Doing a Trace on MyNewSWF.parent:

After calling Application.application.addChild(MyNewSWF);


I get the following:

MyNewSWF.parent -TransformManagerTest1


(TransformManagerTest is the name of the Flex Application I am testing.)

Link to comment
Share on other sites

Ah, yes, it's due to another bug in Flex which can improperly report the parent for a few frames while the parent instantiates. But I believe I figured out a way to work around it internally. Please download the latest build and let me know if it solves the problem for you. (use the link from the e-mail I sent you)

Link to comment
Share on other sites

Did not receive any emails since buying the software or singing on to the form. I got one message from info@greenstock.

Please send Link again to one of my Addresses: Yahoo.com or intradenver.com.



Link to comment
Share on other sites

Sent you another e-mail.

Link to comment
Share on other sites

Thank you for the files It looks like it worked, But now it is placing the text in the wrong place on the screen.


//--- move the selection to the middle of the screen to rotate it -----
myManager.moveSelection((myManager.width / 2),(myManager.height / 2));

// --rotate selection -- 

//--- move item back to 0,0 to move it to the correct location of x100,y100) --- 
myManager.moveSelection(-(myManager.width / 2),-(myManager.height / 2));

//--- move item to final point of x100,y100) ---


trying to moe it to x=100, y=100 it ends up at

x="113.7" y="100.85000000000001"


--- if I just move it to 100,100 and rotate it ( this was working before the update - just causing errors. ) ----

x="213.70000000000002" y="153.85000000000002"


Placing SWF files seem to work fine with the following:

(would be great to get them exact but can live with it)

(placed at x="248.8" y="298.35" it will report being placed at x="248.9" y="298.45" a .1 difference)


var iRotation:Number = xmMainlist.@rotation;
var RotateRadians:Number = iRotation * Math.PI / 180;





Link to comment
Share on other sites

  • 2 weeks later...

I bet your item is running into the bounds. Remember, FlexTransformManager won't allow items to go past its edges. So let's say your FlexTransformManager is 300 pixels wide and tall and you load an image in that's 200 pixels wide and then try to moveSelection(200, 200), it'll actually end up only moving it 100 pixels in each direction. Then if you try moving it backwards (-200, -200), it will again only go 100 pixels either way assuming it started at 0, 0. It protects rotations from going outside the bounds too, just so you know.


As for the numbers being slightly off, it is likely just due to floating point rounding issues which are next to impossible to avoid.


I tried your code and it worked exactly as expected. As long as I wasn't violating the bounds, it went right back to where it was supposed to be. Also remember that rotations occur using the center of the object as the axis, so if the object's registration point is in the upper left (or anywhere other than the center), the x/y properties will be affected by rotations.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.