Looking for the perfect fashion jewelry piece? Check Baloka.com By Maria Mizrahi
Powered by MaxBlogPress  
  • MyLineRider

  • Flex 3 Example: Drawing a polygon at run time with adding and deleting points capability

29th August 2009

Flex 3 Example: Drawing a polygon at run time with adding and deleting points capability

posted in Flash, Flex |

I was on vacation for a couple of weeks, but I am back.

Continuing from my last example Flex 3 Example: Drawing a path at run time with adding and deleting points capabilities, I expanded the code to allow creating polygons at run time.

To create a polygon, the previous code was enhanced with graphics.endFill(); on the RedrawPath method.

I had to include additional methods to finish the polygons, as well as a method to create the last insert anchor point when finishing a polygon and more.

Below is the application to play with. To start, click on the “Add Polygon” button and then click on the stage to add points. At any time you can move any anchor (even as you are creating a polygon) to edit your polygon or any insert anchor point (light red dots) to insert additional anchor points. To end drawing a polygon click the “END” key.

Once a polygon is created in can be fully edited. Anchor points can be moved, inserted and deleted. The code is fully commented and thus I don’t go into explaining how it works in here. If you have questions post them via comments.

Get the code here.

[Post to Twitter]   [Post to Plurk]   [Post to Digg]   [Post to ping.fm]

This entry was posted on Saturday, August 29th, 2009 at 11:06 am and is filed under Flash, Flex. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

There are currently 13 responses to “Flex 3 Example: Drawing a polygon at run time with adding and deleting points capability”

Why not let us know what you think by adding your own comment! Your opinion is as valid as anyone elses, so come on... let us know what you think.

  1. 1 On October 29th, 2009, forrest said:

    Hey,
    I have to say – this is a great class for drawing polygons.
    But what is my problem – I am using it in an AIR application and when I minimize it, there are some errors.
    For example – i draw a polygon and then minimize the window. After this I maximize it again, want to move some anchors and then this runtime error appears:

    ReferenceError: Error #1056: Cannot create property 8589934590 on __AS3__.vec.Vector..
    at Polygon/onAnchorMove()

    I think that after minimizing I lose the Polygon class object. Do you think why this happens?
    Thanks!

  2. 2 On November 18th, 2009, Gilbert Mizrahi said:

    forrest,

    In order to determine what the problem could be I would need to see how you are using it in your AIR app.

    Gilbert

  3. 3 On November 19th, 2009, forrest said:

    Hello Gilbert,
    thank you for your answer.
    I am implementing the Polygon class the same way you did it in your Flex application.
    My problem is that after I minimize the application several times the polygon disappears.
    I am still trying to fix this.

  4. 4 On December 2nd, 2009, t-nor said:

    i got an error at the runtime :

    ReferenceError: Error #1065: variable flash.display::GraphicsPathCommand undefined.

    How could i fix it please ?

  5. 5 On December 16th, 2009, Gilbert Mizrahi said:

    t-nor,

    Can you post your code, so I can see what could be causing the error?

    Gilbert

  6. 6 On December 16th, 2009, lordB8r said:

    Not sure why, but when I clicked view source, I got the nasty 404 error. Is it still up? It looks extremely promising. Cheers!

  7. 7 On December 16th, 2009, Jonathan said:

    Really like this series of posts. Awesome JOB! Trying to figure out how I will get all the polygons and their points. Keep rockin!

  8. 8 On December 17th, 2009, Gilbert Mizrahi said:

    lordB8r,

    The code it still up there. the URL is http://mylinerider.com/swfs/drawingPolygons/srcview/

    Gilbert

  9. 9 On December 17th, 2009, lordB8r said:

    Sorry, I should clarify, but the view source doesn’t work from the example (right click -> view source). Keeps taking me here:

    http://mylinerider.com/2009/08/29/flex-3-example-drawing-a-polygon-at-run-time-with-adding-and-deleting-points-capability/srcview/index.html

    The link you have: Get source code here works.

    Maybe it’s just my machine. But regardless, I like the example. Thanks and keep up the creative juice flows!

  10. 10 On January 13th, 2010, Andre said:

    Great Example.
    Perhaps you can also show, how to use this polygon to crop a part of an image.

  11. 11 On January 13th, 2010, Gilbert Mizrahi said:

    Andre,

    Thanks. I will think about that.

  12. 12 On February 1st, 2010, Jerry Harper said:

    Andre

    Thanks

    It appears that you us some objects that are not part of flex 3.2 GraphicsPathCommand seems only to be in Flex 3.5.

    How do you use 3.5 objects in Flex Builder 3?

  13. 13 On February 3rd, 2010, Gilbert Mizrahi said:

    Jerry,

    I am using flex 3.3. In order to have access to GraphicsPathCommand you need to use Flash Player 10. Check the Flex compiler property and make sure the “Require Flash Player version” is 10.0.0

Leave a Reply

  • About Me

  • Hi, I'm Gilbert Mizrahi and I created this blog to comment about technology and internet marketing. Additionally, I will post Flash/Flex experiments and in most cases they will refer to baloka.com, my wife's site- hey I have to promote the brand:)

google

google

asus