Tuesday, February 14, 2012

Transform Tool - Z-order

Hello! 
Example below shows how to simply add z-order functionality such as bring to front, send to back, etc. using action content.
Press view source context menu to get source code. 

SWC: Transform Tool 2 version 2.5.0.
Source code: Project home page.
ASDoc:  API ASDoc.
Required Flex SDK version: SDK 4.5

16 comments:

  1. Hi Vladomyr,

    I am following your post for last few weeks and your work seems quite interesting. While testing this component, I am not using any on screen mxml elements as target, but i am trying to set the target to components added on runtime for example,
    var sSprite:Sprite = new Sprite; container.addChild(sSprite); sSprite.graphics.beginFill(0xFF0000); sSprite.graphics.drawRect(0,0,200,200); sSprite.graphics.endFill(); sSprite.addEventListener(MouseEvent.MOUSE_DOWN, select);

    protected function select(event:MouseEvent):void
    {
    if(!tool.target || tool.target != event.target)
    {
    tool.target = event.target as UIComponent;
    tool.visible = true;
    tool.startMoving(event);
    }
    }

    Below is the error I am getting when selecting:

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at com.vstyran.transform.utils::TransformUtil$/transformData()[C:\Users\Xyuha\Adobe Flash Builder 4.5\TransformTool\src\com\vstyran\transform\utils\TransformUtil.as:57]
    at com.vstyran.transform.connectors::DataConnector/transfrom()[C:\Users\Xyuha\Adobe Flash Builder 4.5\TransformTool\src\com\vstyran\transform\connectors\DataConnector.as:188]
    at com.vstyran.transform.connectors::UIConnector/transfrom()[C:\Users\Xyuha\Adobe Flash Builder 4.5\TransformTool\src\com\vstyran\transform\connectors\UIConnector.as:197]
    at com.vstyran.transform.view::TransformTool/http://www.vstyran.com/flex/tt/internal::doTransformation()[C:\Users\Xyuha\Adobe Flash Builder 4.5\TransformTool\src\com\vstyran\transform\view\TransformTool.as:665]
    at com.vstyran.transform.controls::Control/moveHandler()[C:\Users\Xyuha\Adobe Flash Builder 4.5\TransformTool\src\com\vstyran\transform\controls\Control.as:390]

    ReplyDelete
    Replies
    1. Hi, I gues your are trying to convert Sprite to UIComponent in
      tool.target = event.target as UIComponent;

      Result of this convertation would be null. You need to wrap your sprite into UIComponent and them pass it as target for transformation.

      Delete
    2. Thanks Volodymyr,

      Can I make change so that it takes any object as target?

      Abinash

      Delete
    3. You can use DataConnector and manually create data for tool and after transformation (event TransformEvent.TRANSFORMATION) apply data on your UI element (Sprite). Connector simples you can find here http://vstyran-flex.blogspot.com/2011/10/transform-tool-2-sample-2.html.

      Advanced solution would be creating custom connector that will take your object as target and interacts with tool internally.

      Delete
  2. Hello Volodymyr,

    I have a question about the method updateTool.

    My working context is the following : I have a UITransformTool object that handles the transformations on an image (photo). This UITransformTool is in a Group.

    My need : the Group can be resized. I would like the UITransformTool to resize in the same time.

    In the doc, I see that the method updateTool is a candidate to perform the job. But setting updateTool(true) does nothing when I resize the Group.

    My question : is there a way to do this with the current version ?

    Thanks in advance for your help,

    Hieu

    ReplyDelete
    Replies
    1. It should work, I will test it and go back to you.

      Delete
  3. It works for me. Can you send me more details on email vstyran@gmail.com

    ReplyDelete
    Replies
    1. Ok I'll send you pieces of my code.

      Thanks for your time.

      Hieu.

      Delete
  4. Hi Volodymyr

    This is an impressive tool and thanks for sharing it with us. I wonder if you can help me with the following.

    I need to create a skin where there are custom icons for the handles(Images) and the 4 corners will rotate and the 4 mid points will resize.

    I am new to skinning as well. I tried to look at the source of your skinning example (Monday, March 22, 2010) but it throws an error.

    And is there a way to switch off the tool tip while performing the transform

    Thanks in advance.

    Dulan

    ReplyDelete
    Replies
    1. Hi, see my post at
      http://vstyran-flex.blogspot.com/2012/02/transform-tool-skinning.html

      Delete
  5. Awesome! Thanks a lot for this tute.

    Is there a feature that sets the transform value by calling a function or a setter

    E.g. control.setRotation(60) will rotate the target by 60?

    Thanks again for the help :)
    Dulan

    ReplyDelete
    Replies
    1. No, but you can change rotation of target and then call updateTool() that will place tool just right under target. To change rotation or other properties around some anchor point(in your case rotate around center) you can use DisplayData class as in following example

      var data:DisplayData = DataUtil.createData(target);
      data.rotate(60);
      DataUtil.applyData(target, data);
      tool.updateTool();

      Delete
  6. Dude.. you've thought about everything.. Thanks man.. I was wondering what the DataUtil was about. and there're some other utils as well.

    Thanks a lot this was helpful .. Thumbs up

    Dulan

    ReplyDelete
    Replies
    1. Utils used internally in tool component but DataUtil can be helpful for you, following methods:
      createData()
      applyData()
      applyScaledData()
      rectangleToData()
      Some of them used to create DisplayData object and some of them to apply properties from DisplayData on your UI object.

      The most important class is DisplayData, it has a lot of methods that can help you for example rotate/resize around anchor point, get bounding box, calculate union etc.

      Delete
  7. Hi Volodymyr,
    This from Bijoy.

    Your tool is very useful. Thanks for your contribution.
    It will be great If you provide a reference document.

    Can u tell me how do I add an action content through action script code?

    Thanks in Advance.

    ReplyDelete
  8. wow i am really beginner here with flex ...... still i can use tools smoothly so clean and friendly help written as well as cool functionalities.......

    ReplyDelete