12 Replies Latest reply on Mar 3, 2009 8:38 AM by bboldi

    Cannot set TextField rotation and size correctly

    bboldi Level 1
      I serialize the _width _height and _rotation of a textbox into a string, and when I load it back, the rotation is OK, but the size is all different (sometimes bigger, sometimes smaller)... the textfield is created using createTextField ... the routine I use to serialization works for all other movieclips.... anyone has some idea??? thanks verry much for your help.
        • 1. Re: Cannot set TextField rotation and size correctly
          Ned Murphy Adobe Community Professional & MVP
          Do you have any code to offer for what you are doing?
          • 2. Re: Cannot set TextField rotation and size correctly
            bboldi Level 1
            ok, the code is quite complicated, it's a VISIO like designer, so I cannot post the entire code here, but here are some additional info:

            first I collect all the _width , _height , _rotation data of the movie clips and textboxes in a movieclip, then I serialize it using JSON.as . When I deserialize the text, and create the objects again, everything is fine, only TextField 's _width, and _height is different. I've noticed that the amount of the difference is based on the rotation angle...

            the save code part:

            for each element

            ...
            newElementArray._width = theelementobject._width;
            newElementArray._height = theelementobject._height;
            newElementArray._xscale = theelementobject._xscale;
            newElementArray._yscale = theelementobject._yscale;
            newElementArray._rotation = theelementobject._rotation;
            ...

            outArray['element'+i]= newElementArray;

            ..then on the end
            var js = new JSON();
            outStr = js.stringify(outArray);

            .. and I store this string somewhere

            ----

            the load code:

            var js = new JSON();
            var inObject = js.parse(dataStr);

            ...

            foreach object, i attach the movie clip to the container than i set the properties:

            ...

            theComponent.setSize(theElement._width,theElement._height);
            theComponent._rotation = theElement._rotation;


            ... i've even tried using _xscale and _yscale, tried to simply set _width, _height, and changing the order of rotation and setSize... didn't helped, the rotation is ok, but the size will be different...

            i hope the problem is understandable... I cannot paste the whole source here...

            thanks in advance...
            • 3. Re: Cannot set TextField rotation and size correctly
              kglad Adobe Community Professional & MVP
              assign rotation first, then dimensions.
              • 4. Re: Cannot set TextField rotation and size correctly
                bboldi Level 1
                Thanks, but changing the rotation and setsize order Does not help. Any other idea?
                • 5. Re: Cannot set TextField rotation and size correctly
                  kglad Adobe Community Professional & MVP
                  use the trace() function to ensure the variables are correct. if they are, check your setSize() method.
                  • 6. Re: Cannot set TextField rotation and size correctly
                    bboldi Level 1
                    I've solved it.

                    the _width and _height of a textfield will return the dimensions of the smallest rectangle that can be drawen around the textbox, so if it's rotated, then it will return wrong values. All I needed to do was to save the rotation angle into a temporary value, then rotaten the textfield back to 0, THEN read the dimensions, and then rotate it back...

                    Thank for your help!
                    • 7. Re: Cannot set TextField rotation and size correctly
                      kglad Adobe Community Professional & MVP
                      that's why i told you to rotate it first, then assign its dimension.
                      • 8. Re: Cannot set TextField rotation and size correctly
                        bboldi Level 1
                        It was a good starting point, and thank you for your help, but Interestingly rotating first when setting the dimensions doesn't help. You have to rotate it back to ZERO degrees, then read the dimensions, that helps.
                        • 9. Re: Cannot set TextField rotation and size correctly
                          kglad Adobe Community Professional & MVP
                          it shouldn't make a difference. you were rotating and then reading the width/height.

                          re-creating the textfield, rotating and then setting the width/height should yield the same textfield size.

                          i just tested that and you're correct. it doesn't yield a textfield with the same dimensions.

                          and what's even more bizarre is flash handles textfields and movieclips differently when re-sizing a rotated object.
                          • 10. Cannot set TextField rotation and size correctly
                            bboldi Level 1
                            I'm so tired of this unlogical behavior... I have been using a few programming languages and IDEs in my life, but actionscript is FAR the worst I've ever seen... It's illogical,IT has no IntelliSense (!!!), and debugging is a pain in the a**. No effense, but Abode could learn a LOT from microsoft's Visual Studio IDE... coding in that enviroment is a dream ;) ok, i stoped with complains, I've found another "interresting" thing though:

                            I used (_root._widht - window._width) / 2 and (_root._height- window._height) / 2 to place a window component on the center of the screen, and it worked FINE, until I placed a textfield object on the _root, then_root._width and _root._height started to returned an incredebly large number - It was 640px originally, and the returned value was a larger number than 10000 ??? WTF? I solved this issue by using Stage.width , but i tought it is worth mentioning.

                            Thanks again for Your help.
                            • 11. Re: Cannot set TextField rotation and size correctly
                              kglad Adobe Community Professional & MVP
                              _root dimensions will depend on the objects on the _root timeline and will be (or should be) the dimensions of the smallest bounding rectangle that encompasses all objects present on the main timeline when that code executes.
                              • 12. Re: Cannot set TextField rotation and size correctly
                                bboldi Level 1
                                You're right,but FYI the text field was placed on the center of the screen... that should not modify the _root._width to 10000px ....