tomato

Suggestions for setting transform properties programatically?

Recommended Posts

Driving myself crazy here trying to integrate the TransformManager into a legacy Flex project. I've finally resorted to eliminating the Flex part that TransformManager has to deal with (or so I think). So...

 

What I need to do is

1. Save and restore transformation data NOT using the built in XML scheme

2. Enable user control through NumericSteppers in addition to direct interaction.

 

 

I've try to go easy on the code below. The settings are stored in an Object. The "canvas" is a Flex SpriteVisualElement. It can change in size if the user opts for "full screen" mode – so property settings are stored as percentages and the current values are derived from the current size of the "canvas". The items being managed by the TransformManager are nested custom classes inherited from Sprite:

 

And item is structured like this:

CustomBaseClass  – Sprite

      CustomSuperClass    – Sprite 

            BitmapClass         – Sprite - loads & parents a Bitmap

            VectorClass          – Sprite - loads & parents a SWF

 

 

The results are erratic – things jump all over, the proportions get distorted. Is there an order of operations I should follow? Or a better ways of doing this? I guess I can cram all the code into one class if that would work.

 

Am I doing this Wrong?

            var newX:Number = canvas.width * (_winEvent.percentRect.x/100);
            var newY:Number = canvas.height * (_winEvent.percentRect.y/100);
            var newWidth:Number = canvas.width * (_winEvent.percentRect.width/100);
            var newHeight:Number = canvas.height * (_winEvent.percentRect.height/100);
            var newRot:Number = _winEvent.rotation;


          _transformItem.x = newX;
          _transformItem.y = newY;
          _transformItem.width = newWidth;
          _transformItem.height = newHeight;
    
          // reset rotation
          _transformItem.rotation = 0;
          _transformItem.rotation = newRot;

          //  have tried the 'rotate' function too
          //_transformItem.rotate(radians);

         // **have tried calling 'update'
        //_transformItem.update();

           // ** have also tried
          // transformManager.updateSelection(true)

Share this post


Link to post
Share on other sites

In order to get the proper behavior, you really need to record/apply the matrix values rather than simple width/height/x/y/rotation. Otherwise you risk not getting the proper skew which happens when users select multiple elements with different rotations and then scale them. 

 

If you still need help, please create a reduced test case FLA, zip it and attach it here so we can see what's going on. And please don't use Flex at all if you can avoid it. (you can attach files by clicking the "more reply options" button below)

Share this post


Link to post
Share on other sites

Thanks for the reply. I've tried to work up a test file to show the problem/task but there are too many elements to do that easily.

 

Let me distill my question: how can I set display properties programatically (x, y, width, height, rotation) on a Sprite object that is managed by the TransformManager?

 

– only one Sprite object is selected at a time

– all Sprite objects are registered with the TransformManager when they are created

Share this post


Link to post
Share on other sites

Perhaps something like this(?):

var item:TransformItem = yourTransformManager.getItem(yourDisplayObject);
item.rotation = whatever;
item.x = whatever;
item.scaleX = whatever; 
...etc...

Share this post


Link to post
Share on other sites

Thanks. Trying that and still getting weirdness – things scaling when they shouldn't, rotation odd when using the NumStepper.

 

Have roughed out a test case – it's a Flex project in Flash Builder – though the elements that TransformManager sees are all AS3.

 

Appreciate any help or tips you can offer!

TransformManagerIssue.fxp.zip

Share this post


Link to post
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.