14 Replies Latest reply on Oct 19, 2007 6:40 AM by Newsgroup_User

    How do I do I make circle and fill

    Level 7
      Hello
      I want do draw a circle on ballons and detecting there presence inside the
      circle.

      just like this http://www.flashgames247.com/play/823.html

      How do I do that.

      Please help.


        • 1. Re: How do I do I make circle and fill
          Level 7
          flashcrazy,

          > I want do draw a circle on ballons and detecting there
          > presence inside the circle.
          >
          > just like this http://www.flashgames247.com/play/823.html

          That's a pretty advanced goal! I'm not the programmer of that game, so
          I don't know for sure, but here's my guess at a basic outline. The Drawing
          API lets the mouse draw a series of lines. See the MovieClip class in the
          ActionScript 2.0 Language Reference; you'll see a lineTo() method, and that
          will get you started (you didn't specify what language you're dealing with,
          so I'm assuming AS2). Once the lines intersect, the closed shape is filled.
          The filled shaped appears inside a movie clip container -- because that's
          how the Drawing API works -- which means the shape can have
          MovieClip.hitTest() invoked on it. A hit test is performed on each of the
          balloons. If more than one balloon passes the hit test, a dynamic property
          (probably) is checked to see if the balloons have the same color.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: How do I do I make circle and fill
            Level 7
            This is a multi-part message in MIME format.

            ------=_NextPart_000_001C_01C80BF5.831147E0
            Content-Type: text/plain;
            charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            Thnaks Mr Stiller

            The Drawing API lets the mouse draw a series of lines. See the =
            MovieClip class in the=20
            > ActionScript 2.0 Language Reference; you'll see a lineTo() method,
            --- have already done the part of Drawing lines and Intersecting It.

            and that will get you started (you didn't specify what language you're =
            dealing with,=20
            > so I'm assuming AS2). --I am using as3 in flash cs3

            Once the lines intersect, the closed shape is filled. -- I used color =
            to change the color of the mc but how to fill it ?

            The filled shaped appears inside a movie clip container -- because =
            that's=20
            how the Drawing API works -- which means the shape can have=20
            MovieClip.hitTest() invoked on it. A hit test is performed on each of =
            the=20
            > balloons. -------- Which handle can probably do this work ? What is =
            the effect on performance in terms of memory ?

            If more than one balloon passes the hit test, a dynamic property=20
            > (probably) is checked to see if the balloons have the same color. =
            -------- the different ballons can be dynamically created mc or being =
            attached mc .In any case do we have to loop throufg each instance of =
            balloon to see hitTest ?




            I
            "David Stiller" <stiller@quip-remove-.net> wrote in message =
            news:feij9t$pce$1@forums.macromedia.com...
            > flashcrazy,
            >=20
            >> I want do draw a circle on ballons and detecting there
            >> presence inside the circle.
            >>
            >> just like this http://www.flashgames247.com/play/823.html
            >=20
            > That's a pretty advanced goal! I'm not the programmer of that =
            game, so=20
            > I don't know for sure, but here's my guess at a basic outline. The =
            Drawing=20
            > API lets the mouse draw a series of lines. See the MovieClip class in =
            the=20
            > ActionScript 2.0 Language Reference; you'll see a lineTo() method, and =
            that=20
            > will get you started (you didn't specify what language you're dealing =
            with,=20
            > so I'm assuming AS2). Once the lines intersect, the closed shape is =
            filled.=20
            > The filled shaped appears inside a movie clip container -- because =
            that's=20
            > how the Drawing API works -- which means the shape can have=20
            > MovieClip.hitTest() invoked on it. A hit test is performed on each of =
            the=20
            > balloons. If more than one balloon passes the hit test, a dynamic =
            property=20
            > (probably) is checked to see if the balloons have the same color.
            >=20
            >=20
            > David Stiller
            > Adobe Community Expert
            > Dev blog, http://www.quip.net/blog/
            > "Luck is the residue of good design."=20
            >=20
            >
            ------=_NextPart_000_001C_01C80BF5.831147E0
            Content-Type: text/html;
            charset="iso-8859-1"
            Content-Transfer-Encoding: quoted-printable

            <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
            <HTML><HEAD>
            <META http-equiv=3DContent-Type content=3D"text/html; =
            charset=3Diso-8859-1">
            <META content=3D"MSHTML 6.00.2900.2096" name=3DGENERATOR>
            <STYLE></STYLE>
            </HEAD>
            <BODY>
            <DIV><FONT face=3DArial size=3D2>Thnaks Mr Stiller</FONT></DIV>
            <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
            <DIV><FONT face=3DArial size=3D2>The Drawing API lets the mouse =
            draw a series=20
            of lines.  See the MovieClip class in the <BR>&gt; ActionScript 2.0 =

            Language Reference; you'll see a lineTo() method,</FONT></DIV>
            <DIV><FONT face=3DArial size=3D2><STRONG>--- have already done the part =
            of Drawing=20
            lines and Intersecting It.</STRONG></FONT></DIV>
            <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
            <DIV><FONT face=3DArial size=3D2> and that  will get you =
            started (you=20
            didn't specify what language you're dealing with, <BR>&gt; so I'm =
            assuming=20
            AS2).<STRONG> --I am using as3 in flash cs3</STRONG></FONT></DIV>
            <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
            <DIV><FONT face=3DArial size=3D2> Once the lines intersect, the =
            closed shape is=20
            filled.  <STRONG>-- I used color to change the color of the mc but =
            how to=20
            fill it ?</STRONG></FONT></DIV>
            <DIV><BR><FONT face=3DArial size=3D2> The filled shaped appears =
            inside a movie=20
            clip container -- because that's <BR> how the Drawing API works -- =
            which=20
            means the shape can have <BR> MovieClip.hitTest() invoked on =
            it.  A=20
            hit test is performed on each of the <BR>&gt; balloons.  =
            <STRONG>--------=20
            Which handle can probably do this work ? What is the effect on =
            performance in=20
            terms of memory ?</STRONG></FONT></DIV>
            <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
            <DIV><FONT face=3DArial size=3D2>If more than one balloon passes the hit =
            test, a=20
            dynamic property <BR>&gt; (probably) is checked to see if the balloons =
            have the=20
            same color.<STRONG> -------- the different ballons can be dynamically =
            created mc=20
            or being attached mc .In any case do we have to loop throufg each =
            instance of=20
            balloon to see hitTest ?</STRONG></FONT></DIV>
            <DIV><FONT face=3DArial><BR><BR><FONT =
            size=3D2></FONT></FONT> </DIV>
            <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
            <DIV><FONT face=3DArial size=3D2>I</FONT></DIV>
            <DIV><FONT face=3DArial size=3D2>"David Stiller" &lt;</FONT><A=20
            href=3D"mailto:stiller@quip-remove-.net"><FONT face=3DArial=20
            size=3D2>stiller@quip-remove-.net</FONT></A><FONT face=3DArial =
            size=3D2>&gt; wrote in=20
            message </FONT><A href=3D"news:feij9t$pce$1@forums.macromedia.com"><FONT =

            face=3DArial =
            size=3D2>news:feij9t$pce$1@forums.macromedia.com</FONT></A><FONT=20
            face=3DArial size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt;=20
            flashcrazy,<BR>&gt; <BR>&gt;&gt; I want do draw a circle on ballons and=20
            detecting there<BR>&gt;&gt; presence inside the =
            circle.<BR>&gt;&gt;<BR>&gt;&gt;=20
            just like this </FONT><A =
            href=3D" http://www.flashgames247.com/play/823.html"><FONT=20
            face=3DArial =
            size=3D2> http://www.flashgames247.com/play/823.html</FONT></A><BR><FONT=20
            face=3DArial size=3D2>&gt; <BR>&gt;    That's a pretty =
            advanced=20
            goal!  I'm not the programmer of that game, so <BR>&gt; I don't =
            know for=20
            sure, but here's my guess at a basic outline.  The Drawing <BR>&gt; =
            API=20
            lets the mouse draw a series of lines.  See the MovieClip class in =
            the=20
            <BR>&gt; ActionScript 2.0 Language Reference; you'll see a lineTo() =
            method, and=20
            that <BR>&gt; will get you started (you didn't specify what language =
            you're=20
            dealing with, <BR>&gt; so I'm assuming AS2).  Once the lines =
            intersect, the=20
            closed shape is filled. <BR>&gt; The filled shaped appears inside a =
            movie clip=20
            container -- because that's <BR>&gt; how the Drawing API works -- which =
            means=20
            the shape can have <BR>&gt; MovieClip.hitTest() invoked on it.  A =
            hit test=20
            is performed on each of the <BR>&gt; balloons.  If more than one =
            balloon=20
            passes the hit test, a dynamic property <BR>&gt; (probably) is checked =
            to see if=20
            the balloons have the same color.<BR>&gt; <BR>&gt; <BR>&gt; David=20
            Stiller<BR>&gt; Adobe Community Expert<BR>&gt; Dev blog, </FONT><A=20
            href=3D" http://www.quip.net/blog/"><FONT face=3DArial=20
            size=3D2> http://www.quip.net/blog/</FONT></A><BR><FONT face=3DArial =
            size=3D2>&gt;=20
            "Luck is the residue of good design." <BR>&gt; =
            <BR>&gt;</FONT></BODY></HTML>

            ------=_NextPart_000_001C_01C80BF5.831147E0--

            • 3. Re: How do I do I make circle and fill
              Level 7
              flashcrazy,

              >> The Drawing API lets the mouse draw a series of lines.
              > --- have already done the part of Drawing lines and Intersecting It.

              Okay.

              >> I'm assuming AS2).
              > --I am using as3 in flash cs3

              That's fine. Different syntax from AS2, but the object-oriented
              approach is the same.

              >> Once the lines intersect, the closed shape is filled.
              > -- I used color to change the color of the mc but how to fill it ?

              You said you've got the drawing and intersecting part down. Since
              you're using ActionScript 3.0, that means you're using the Graphics class
              rather than the MovieClip class. The Graphics class features two methods
              for fills: beginFill() and beginGradientFill().

              > -------- Which handle can probably do this work ? [hitTest()]
              > What is the effect on performance in terms of memory ?

              Not sure what you mean by "handle" -- maybe "handler," as in, event
              handlers? In any case, you wouldn't necessarily have to perform your hit
              tests in response to an event. Whatever approach you're using to determine
              intersection, that approach is going to tell you when to loop through the
              balloons. In AS3, movie clips inherit from the DisplayObject class, which
              features two hit test methods: hitTestObject() and hitTestPoint(). If it
              only matters that the balloon's registration point is selected, you'll use
              hitTestPoint(); otherwise, you'll use hitTestObject(). Because balloons are
              round, hitTestObject() may sometimes give you unexpected hits (or misses)
              because it checks for hits in regard to an object's bounding box. There are
              plenty of ways to check for object proximities (e.g. calculating the
              circular or elliptical area from the balloon's registration point) but hit
              testing is a good, rough-and-ready place to start.

              Performance on memory is going to depend largely on the quality of your
              programming and the complexity of your artwork.

              > -------- the different ballons can be dynamically created mc or
              > being attached mc .In any case do we have to loop throufg each
              > instance of balloon to see hitTest ?

              In ActionScript 3.0, there is no attaching -- not in the sense of
              MovieClip.attachMovie(), which was the way to do it in ActionScript 2.0.
              You can certainly pull assets from the Library at runtime, but there is no
              attatchMovie() method in AS3. Instead, you supply a Linkage Class (which
              subclasses MovieClip) and instantiate your asset in the format "new
              LinkageClassName()" (without quotes).

              Unless you come up with another algorithm for shortening your search, I
              should think you would indeed have to loop through each balloon.


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."


              • 4. Re: How do I do I make circle and fill
                Level 7
                David
                Learnt some more from your previous post.Thanks

                I could use AS2 for the type of goal I mentioned ?

                > You said you've got the drawing and intersecting part down. Since
                > you're using ActionScript 3.0, that means you're using the Graphics class
                > rather than the MovieClip class. The Graphics class features two methods
                > for fills: beginFill() and beginGradientFill().
                -----I used them but that makes filling the circle from start point till
                end.I wnat to fill mc after the intersection has occured.
                ------
                What is the effect on performance in terms of memory ?
                -- I noticed 100% CPU usage and swf held up when drawing with cursor rapidly
                which used lineTo etc to draw lines on cursor movement.
                How to prevent it.Any tips on memory related issues.




                >> Which handle can probably do this work ? [hitTest()] - I did it yesterday
                >> but had to loop through each instance.
                Not feeling easy at this approach performace considering.

                Performance on memory is going to depend largely on the quality of your
                programming and the complexity of your artwork.
                ---I havent found any flash documentation on performance,memory terms.
                Can you give some links.

                > In ActionScript 3.0, there is no attaching -- not in the sense of
                > MovieClip.attachMovie(), which was the way to do it in ActionScript 2.0.
                > You can certainly pull assets from the Library at runtime, but there is no
                > attatchMovie() method in AS3. --I used AS2 for achieving the same goal
                > .
                It attach movie but donno why not getting placed on the drawn mc and always
                places at top,left corner(0,0).
                I found the mc to which attaching a new mc mentioned above ,also have the
                cord x,y to be 0,0 .
                Strange I have that mc placed at center of stage.
                I tried globalToLocal() etc to see if this could work but helpless.

                Unless you come up with another algorithm for shortening your search, I
                should think you would indeed have to loop through each balloon. --
                Can u suggest any other algo or approach to achieve my goal.

                Thnaks


                • 5. Re: How do I do I make circle and fill
                  Level 7
                  flashcrazy,

                  > I could use AS2 for the type of goal I mentioned ?

                  Sure thing. The Drawing API and related mechanisms (hitTest(), looping,
                  etc.) are available to both versions of the language.

                  >> beginFill() and beginGradientFill().
                  > -----I used them but that makes filling the circle from
                  > start point till end.I wnat to fill mc after the intersection
                  > has occured.

                  You'll have to omit either of those until you've determined that an
                  intersection or closure has occurred. Determining closure is probably the
                  hardest part of this whole project. It's easy enough to test the proximity
                  of the currently drawn point to the initially drawn point, but that's only
                  one way the figure might close.

                  I can easily envision an intersection somewhere else along the figure's
                  stroke. Imagine, for example, the number 6. See its shape? Imagine
                  someone started to draw a very rough circle from the tip of the 6 downward,
                  toward the left, under and around to the right, then through the middle of
                  the previous arc. The shape of the 6 becomes an enclosed circle, o, and the
                  upper "tail" can be discarded. I'm intrigued by the challenge this poses --
                  this is exactly the sort of puzzle I like to solve; this is why I enjoy
                  programming and do it for a living -- but I haven't tackled that particular
                  problem before and don't have a ready answer.

                  Once you determine intersection/enclosure, *that's* when you'll redraw
                  the shape with a fill.

                  > -- I noticed 100% CPU usage and swf held up when
                  > drawing with cursor rapidly which used lineTo etc to
                  > draw lines on cursor movement.

                  Yes, that would worry me, too.

                  > How to prevent it.Any tips on memory related issues.

                  Memory management is one of those basic skills that many people seem to
                  overlook, because (for the most part) Flash Player takes care of that.
                  Sometimes you'll spike simply because of the complexity of your artwork
                  (likes of complex gradients, alpha transparency, filter effects). Sometimes
                  you'll spike because you're constantly instantiating new objects when you
                  should be re-using old ones. There are dozens of ways you might be pushing
                  Flash Player.

                  Programming isn't an easy discipline, for sure. I'm thrilled that Flash
                  has opened the doors, over the years, to thousands of multimedia enthusiasts
                  who might not otherwise be programmers (myself included). That said, it's a
                  bit like taking on a hobby that requires some technical skill ... this is
                  probably a weak analogy, but if you're into cycling, you're going to
                  ultimately have more fun -- after the initial learning curve -- if you can
                  patch or replace punctured tubes, oil the chain, adjust the seat, and so on.

                  By saying any of this, I don't mean to imply anything about your own
                  personal skills. With programming, the learning curve never ends -- not for
                  me, not for anyone. I have no idea what your strengths are. You might be
                  an expert programmer in another platform. You might just be starting out.
                  Makes no difference to me ... I just enjoy nudging people in the right
                  direction when I can, because Flash is so much fun.

                  Here are a few links on Flash memory management in general:

                  http://www.adobe.com/devnet/flashplayer/articles/garbage_collection.html
                  http://www.kaourantin.net/2005/09/garbage-collection-in-flash-player-8.html
                  http://timotheegroleau.com/Flash/articles/scope_chain.htm

                  > Not feeling easy at this approach [hitTest] performace
                  > considering.

                  Agreed, but hitTest may not be the problem at all. You wouldn't be
                  looping through the balloons until *after* the shape had been closed. By
                  that point, your currently-high-CPU-cycles drawing routine will have ended.

                  > ---I havent found any flash documentation on performance,
                  >memory terms. Can you give some links.

                  See above. :)

                  > It attach movie but donno why not getting placed on the
                  > drawn mc and always places at top,left corner(0,0).

                  When I spoke of attaching, I thought you were referring to the balloons.
                  Not sure where "drawn mc" fits in, if by that you mean the movie clip that
                  contains the shape drawn by the user. The balloons and the drawing
                  shouldn't be in the same movie clip at all, otherwise you couldn't run
                  hitTest() on them (children of the same movie clip would be fine, but they
                  shouldn't be *in* the same movie clip).

                  > I found the mc to which attaching a new mc mentioned
                  > above ,also have the cord x,y to be 0,0 . Strange I have
                  > that mc placed at center of stage. I tried globalToLocal()
                  > etc to see if this could work but helpless.

                  At this point, flashcrazy, I would encourage you to break down your main
                  goal -- the game -- into smaller subgoals, making sure to get comfortable
                  with each step in isolation before combining them. I regularly take the
                  same approach in my programming: if something doesn't make sense, I pull
                  that concept aside and often re-create a brand new FLA that illustrates only
                  the portion causing me trouble. More often then not, this isolation
                  approach brings something to light I didn't see when looking at the whole
                  (more complex) project.

                  >> Unless you come up with another algorithm for shortening
                  >> your search, I should think you would indeed have to loop
                  >> through each balloon. --

                  > Can u suggest any other algo or approach to achieve my goal.

                  Looping is definitely the way I'd go.


                  David Stiller
                  Adobe Community Expert
                  Dev blog, http://www.quip.net/blog/
                  "Luck is the residue of good design."


                  • 6. Re: How do I do I make circle and fill
                    Level 7
                    >>> beginFill() and beginGradientFill().
                    >> -----I used them but that makes filling the circle from
                    >> start point till end.I wnat to fill mc after the intersection
                    >> has occured.
                    --started beginFill() but it keeps filling color as soon as i clip till
                    leave the mose and even joins the line.I read this is beginFill() property
                    to put closure by itself to fill.

                    > You'll have to omit either of those until you've determined that an
                    > intersection or closure has occurred. Determining closure is probably the
                    > hardest part of this whole project. It's easy enough to test the
                    > proximity of the currently drawn point to the initially drawn point, but
                    > that's only one way the figure might close. -- I have detectetd the
                    > closure by storing the coordinates moved on mouse move to an array.
                    All workig fine if the cursor movement is not ver fast.The problem comes
                    when user moves corsor so fast that values are not able to get soterd with
                    matciing spped to Array.


                    >> I found the mc to which attaching a new mc mentioned
                    above ,also have the cord x,y to be 0,0 . Strange I have
                    that mc placed at center of stage. I tried globalToLocal()
                    etc to see if this could work but helpless.
                    > > At this point, flashcrazy, I would encourage you to break down your
                    > > main
                    > goal -- the game -- into smaller subgoals, making sure to get comfortable

                    ----I did same but could trace a valid reason except that something might be
                    for cord of mc and cord of Stage.

                    > David Stiller
                    > Adobe Community Expert
                    > Dev blog, http://www.quip.net/blog/
                    > "Luck is the residue of good design."
                    >


                    • 7. Re: How do I do I make circle and fill
                      Level 7
                      flashcrazy,

                      > --started beginFill() but it keeps filling color as soon as i clip
                      > till leave the mose and even joins the line.I read this is beginFill()
                      > property to put closure by itself to fill.

                      I'm afraid my understanding of your needs is starting to fade. When you
                      say, "as soon as i clip till leave the mose and even joins the line," I'm
                      not sure I can grasp what you're describing. I *think* you're saying the
                      beginFill() method connects each new vertex as you draw it, and that you
                      only want it to fill after an enclosed shape has been drawn. If I've
                      understood that, then yes, that's how the beginFill() method behaves, which
                      is why you'll have to omit that method until you know an intersection has
                      occurred. Only then will you apply the fill.

                      > -- I have detectetd the closure by storing the coordinates moved
                      > on mouse move to an array.

                      Storing those values in an array wouldn't be enough. You would have to
                      compare the current position of the mouse -- actually, the current and
                      previous positions -- against all the positions before those two.

                      > The problem comes when user moves corsor so fast that values are
                      > not able to get soterd with matciing spped to Array.

                      By "soterd," do you mean "sorted"? Are you constantly sorting your
                      array? The crux of this whole project (at least, to my thinking) is going
                      to be the algorithm used to determine enclosure in your drawings. It might
                      be possible to accomplish this without an array -- I really haven't thought
                      it through -- and even if you use an array, you might not have to constantly
                      sort it.

                      > ----I did same but could trace a valid reason except that something
                      > might be for cord of mc and cord of Stage.

                      I'm not sure what you mean by "cord" (maybe "line segment"? -- as in,
                      the chords drawn to the Stage?). I'm not trying to be annoying, it's just
                      that I'm having some difficulty understanding what you've written. The
                      content of my replies is guesswork, as I mentioned at the beginning.
                      Normally, I answer questions that I immediately know the answers to, but I
                      took a chance this time and provided an outline.

                      Would you show the code you're using for determining shape enclosure?
                      We're several replies into a lengthening thread, but you haven't yet shown
                      any ActionScript. If you do, chances are much better I'll be able to see
                      see exactly what you're doing. That way, either I, or anyone else reading
                      this thread, will probably be able to weigh in with definitive code
                      suggestions.


                      David Stiller
                      Adobe Community Expert
                      Dev blog, http://www.quip.net/blog/
                      "Luck is the residue of good design."


                      • 8. Re: How do I do I make circle and fill
                        Level 7
                        I would try to be clear and precise from now.

                        > beginFill() method connects each new vertex as you draw it, and that you
                        > only want it to fill after an enclosed shape has been drawn. -- ye
                        > ,true.How to do that after circle is complete.


                        > Storing those values in an array wouldn't be enough. You would have to
                        > compare the current position of the mouse -- actually, the current and
                        > previous positions -- against all the positions before those two. ---
                        I have stored all x,y cordinates while mouse moves in an array .At mouse up
                        I just check all values of array against all other in arry.If I find a
                        cordinate occurance twice it confirms there was an intersection.That's the
                        logic and is working fine.


                        >> The problem comes when user moves corsor so fast that values are
                        >> not able to get soterd with matciing spped to Array.
                        > By "soterd," do you mean "sorted"? -- Nop, I mean to store mouse
                        > cordinates in array .Array.push()

                        It might be possible to accomplish this without an array -- I dont feel the
                        need to sort array,But would definitaly appreciate a way without array,if it
                        works.

                        I'm not sure what you mean by "cord" --- I menat "coordinates" x, y.

                        The AS for it is following .please ignore for variable declarations since
                        this is just the required portions of code.


                        var c:Number = 0;
                        var cord:Array = new Array();

                        mouseListener.onMouseDown = function() {
                        var x_array:Array = new Array();
                        var y_array:Array = new Array();
                        var finalarray:Array = new Array();
                        c++;
                        cord.push(_xmouse+","+_ymouse);
                        _root.Line.createEmptyMovieClip("LineCreate"+c,10+c);
                        _root.Line["LineCreate"+c].createEmptyMovieClip("InnerMc"+d,10+d);
                        _root.Line["LineCreate"+c].lineStyle(2,0x000000,100,true,"none","round","miter",1); _root.Line["LineCreate"+c].moveTo(_xmouse,_ymouse); this.isDrawing = true; };mouseListener.onMouseMove = function() { if (this.isDrawing) { currCord = _xmouse+","+_ymouse; if (this.isDrawing) { cord.push(currCord); } _root.Line["LineCreate"+c].lineTo(_xmouse,_ymouse); } updateAfterEvent();};mouseListener.onMouseUp = function() { var cc = 0; this.isDrawing = false; onMouseMove = null; for (x=0; x<cord.length; x++) { search = cord[x]; for (y=0; y<cord.length; y++) { if (search == cord[y]) { cc++; if (cc >= 2) { trace("*************** Circle Complete ********************"); x=cord.length+10; break; } //if } //if }//for y cc = 0; }//for x cord.length=0;};

                        • 9. Re: How do I do I make circle and fill
                          Level 7
                          flashcrazy,

                          >> beginFill() method connects each new vertex as you draw it,
                          >> and that you only want it to fill after an enclosed shape has
                          >> been drawn.

                          > -- ye ,true.How to do that after circle is complete.

                          Exactly! That's the hardest part of this project.

                          > I have stored all x,y cordinates while mouse moves in an array .
                          > At mouse up I just check all values of array against all other in
                          > arry.If I find a cordinate occurance twice it confirms there was
                          > an intersection.That's the logic and is working fine.

                          That will catch *some* intersections, but only a very few when compared
                          to the total number of possible intersections. Take a look at the following
                          illustration.

                          http://www.mesnil.demon.co.uk/xtian.gif

                          In that shape -- the ichthus "Christian fish" symbol -- the intersection
                          is obvious to anyone looking at it. The intersection occurs in the fish's
                          tail. Getting ActionScript to see that intersection ... that's the
                          challenge. If you're just recording coordinates every few seconds, then
                          obviously the fish's curves wouldn't be nearly as smooth in the Flash
                          version. It's very possible to imagine that the "X" of the fish's tail is
                          the result of two crossed line segments -- *not* two overlapping
                          coordinates. If you're just looking for duplicated coordinates, you
                          wouldn't find the above intersection.

                          I checked out your code. Off the top of my head, I see two ways to
                          significantly improve performance:

                          A) Reduce the number of coordinates drawn. This means use setInterval()
                          instead of onMouseMove. The game you're trying to emulate does the same
                          thing. It's shapes are comprised of dozens of coordinates, rather than
                          hundreds. You may only need to drop an anchor point every tenth of a second
                          (100 milliseconds) rather than every 10 milliseconds or so.

                          B) Store your numerical values (the coordinates) as numbers, rather than
                          strings. Whatever approach you use toward finding intersections will be
                          quicker when you're comparing number values. (Incidentally, I'm curious
                          about your three arrays x_array, y_array, and finalarray -- they don't
                          appear to be used.)

                          In testing your code as is, just drawing without much thought, I found
                          it pratically impossible to overlap a pair of coordinates.


                          David Stiller
                          Adobe Community Expert
                          Dev blog, http://www.quip.net/blog/
                          "Luck is the residue of good design."


                          • 10. Re: How do I do I make circle and fill
                            Level 7
                            flashcrazy,

                            Here's the beginnings of what you might need.

                            http://id.mind.net/~zona/mmts/intersections/intersectionOfTwoLines1/intersectionOfTwoLines 1.html

                            Think of your line segments in terms of linear functions. As each new
                            line segment is drawn, you'll compare its function to each previous
                            segement -- which is why it's important to reduce the number of coordinates.

                            Now, keep in mind, linear functions describe lines, not line segments.

                            What you're seeing at the moment is how my mind works when I don't know
                            the answer to something. As soon as it's clear to me that comparing
                            coordinates isn't enough, I realize I need to compare lines. Then I
                            realize, almost immediately, that lines aren't the right answer, either:
                            these are line segments. I start Googling "intersection of two line
                            segments" and find this:

                            http://www.cs.wustl.edu/~pless/506/l4.html

                            And so it goes.


                            David Stiller
                            Adobe Community Expert
                            Dev blog, http://www.quip.net/blog/
                            "Luck is the residue of good design."


                            • 11. Re: How do I do I make circle and fill
                              Level 7
                              Those links were good for understanding.
                              But seems will require much more for AS.
                              What will be the complete approach in terms of flash as.
                              Can you summarize ?
                              I need to solve it!!!!!

                              How will each segment determiined for slope.the all slopes agains each other
                              slopes.
                              So many things mixed up.

                              Help.


                              • 12. Re: How do I do I make circle and fill
                                Level 7
                                flashcrazy,

                                > Those links were good for understanding.
                                > But seems will require much more for AS.

                                That's my assessment as well. Flash makes it relatively easy to enter
                                into the world of programming, but programming on any platform is a
                                challenging discipline! Game programming tends to be especially difficult,
                                because of the visually complex user interaction.

                                > What will be the complete approach in terms of flash as.
                                > Can you summarize ?
                                > I need to solve it!!!!!

                                I understand that the solution is important to you! Believe me, if I
                                had a ready answer handy, I would have typed it out for you days ago! I'm
                                not trying to hide an obvious answer from you. I've already explained how I
                                would approach this if the project were mine. This sort of problem-solving
                                is how many people make a living (myself included), and it would take me
                                several hours of research and experimentation to figure out. If I had a
                                math degree, I may very well have solved this already, but I don't. ;)

                                > How will each segment determiined for slope.the all slopes
                                > agains each other slopes.
                                > So many things mixed up.

                                And people think Flash programming is easy!

                                > Help.

                                I've been steering you toward what I feel is the correct direction. For
                                better or worse, I've apparently helped you settle into an ActionScript 2.0
                                approach, rather than 3.0. I've assessed your code in progress. I've given
                                you a number of informative hyperlinks. That's the best I can do without
                                taking a serious chunk out of my work day. :)

                                We've actually come quite a distance in this conversation. Without my
                                input, you may not have realized -- at least, not as quickly -- that
                                comparing discrete coordinates isn't enough to guarantee shape closure.
                                There are a number of math enthusiasts on this forum who may very well know
                                the remaining algorithm(s) immediately. At this point, I suggest you start
                                a new thread that specifically asks for how to test for intersecting line
                                segments.


                                David Stiller
                                Adobe Community Expert
                                Dev blog, http://www.quip.net/blog/
                                "Luck is the residue of good design."


                                • 13. Re: How do I do I make circle and fill
                                  Level 7
                                  David you helped me progresss this thread.Thanks for the information
                                  departed so far.
                                  I am starting a new thread how to test for intersecting line segments.
                                  But my sixth sense says there is something very easy to achive the
                                  goal,already with me .Only thing lacking is it is not coming out of stomach.

                                  Thanks


                                  "David Stiller" <stiller@quip-remove-.net> wrote in message
                                  news:ff7jsj$eel$1@forums.macromedia.com...
                                  > flashcrazy,
                                  >
                                  >> Those links were good for understanding.
                                  >> But seems will require much more for AS.
                                  >
                                  > That's my assessment as well. Flash makes it relatively easy to enter
                                  > into the world of programming, but programming on any platform is a
                                  > challenging discipline! Game programming tends to be especially
                                  > difficult, because of the visually complex user interaction.
                                  >
                                  >> What will be the complete approach in terms of flash as.
                                  >> Can you summarize ?
                                  >> I need to solve it!!!!!
                                  >
                                  > I understand that the solution is important to you! Believe me, if I
                                  > had a ready answer handy, I would have typed it out for you days ago! I'm
                                  > not trying to hide an obvious answer from you. I've already explained how
                                  > I would approach this if the project were mine. This sort of
                                  > problem-solving is how many people make a living (myself included), and it
                                  > would take me several hours of research and experimentation to figure out.
                                  > If I had a math degree, I may very well have solved this already, but I
                                  > don't. ;)
                                  >
                                  >> How will each segment determiined for slope.the all slopes
                                  >> agains each other slopes.
                                  >> So many things mixed up.
                                  >
                                  > And people think Flash programming is easy!
                                  >
                                  >> Help.
                                  >
                                  > I've been steering you toward what I feel is the correct direction.
                                  > For better or worse, I've apparently helped you settle into an
                                  > ActionScript 2.0 approach, rather than 3.0. I've assessed your code in
                                  > progress. I've given you a number of informative hyperlinks. That's the
                                  > best I can do without taking a serious chunk out of my work day. :)
                                  >
                                  > We've actually come quite a distance in this conversation. Without my
                                  > input, you may not have realized -- at least, not as quickly -- that
                                  > comparing discrete coordinates isn't enough to guarantee shape closure.
                                  > There are a number of math enthusiasts on this forum who may very well
                                  > know the remaining algorithm(s) immediately. At this point, I suggest you
                                  > start a new thread that specifically asks for how to test for intersecting
                                  > line segments.
                                  >
                                  >
                                  > David Stiller
                                  > Adobe Community Expert
                                  > Dev blog, http://www.quip.net/blog/
                                  > "Luck is the residue of good design."
                                  >


                                  • 14. Re: How do I do I make circle and fill
                                    Level 7
                                    flashcrazy,

                                    > I am starting a new thread how to test for intersecting line
                                    > segments. But my sixth sense says there is something very
                                    > easy to achive the goal,already with me .

                                    That would be fantastic! :) If so, I too will be curious to see what
                                    it is.

                                    Best of luck!


                                    David Stiller
                                    Contributor, How to Cheat in Flash CS3
                                    http://tinyurl.com/2cp6na
                                    "Luck is the residue of good design."