11 Replies Latest reply on Dec 15, 2006 6:00 AM by Sketchsta

    drawind API help

    Sketchsta Level 1
      I need some help locking rounded corners in drawRectangle function im making.
      when i call the function i want to be able to specify the width and height, and i want the rounded corners to keep the same amount of curve, but i need them to update their position on stage.

      I hope that made sense..

      heres the rounded rectangle i want to make into a function:
        • 1. Re: drawind API help
          Sketchsta Level 1
          This is the function i'm trying to create, but as you can see, i have no idea what to do with the rounded corners..
          • 2. Re: drawind API help
            Peter Lorent Level 2
            Something like attached...

            • 3. Re: drawind API help
              Sketchsta Level 1
              ARE YOU SERIOUS!!??!!??!!??!!

              all that just to create a rounded rectangle????

              ohh man... what did I get myself into???

              ok, first thing.. that whole code has to be saved in an external script right?
              i dont know how to do that.. never looked into it, but it cant be hard..

              second, when i say
              #include "drawRect.as"
              where "drawRect" thats the directory where the script is saved. correct?

              also, this seems ( i havent tried it yet ) like at runtime, the user will be able to draw rectangles??
              I dont need that for what im trying to do.

              creating a rounded rectangle is not too hard, just time consuming, so I thought i'd make it a function so that i can call to it..
              i just want this for the layout of a website im doing, i dont need it to be usable by the users.

              Is it possible however, to have each of these drawn rectangles, dolh data? like text and pictures? and also to have it set to Word Wrap??

              I'm getting this idea in my head, of having a website with windows that can be resized, and moved around by the user..
              I think i read something about that sort of usability in a DHTML overview.. atleast i think it was DHTML.. =)
              • 4. Re: drawind API help
                Peter Lorent Level 2
                The external as:
                In Flash create a new actionscript file (File -> New...) -> copy/paste the posted code -> save as drawRect.as in the same directory as the .fla file.
                Copy/paste the posted code marked //in the fla in the .fla file you have. Test.

                The posted code can be used to dynamically draw windows on the screen (like with a drag handle) but as is the code just draws boxes of any given size on any given position with or without rounded corners with any given radius. When the coder says 'user' he is referring to the coder (you) who is using his class.

                >>Is it possible however, to have each of these drawn rectangles, dolh data? like text and pictures? and also to have it set to Word Wrap??
                In this example the box is drawn on the root. But you can draw the box in any movieclip. That same movieclip can contain other data like text and pictures.
                • 5. Re: drawind API help
                  Sketchsta Level 1
                  yeah i just did it, and it works just like i wanted it to. I never used an external script before.

                  I'm still trying to figure out a way to write a function that works the same as the code in the external .as, but im too new to action script, so i might not have any luck. =)

                  i have made a script (on paper) that draws the curves on stage (havent tried it yet) and from this im hoping to find a way to join the anchors with a lineTo()

                  If I get this to work, it will be my verry first script that i made from scratch. =)

                  wish me luck. =)
                  • 6. Re: drawind API help
                    Level 7
                    Yeah, that is a lot of code to draw a rect with curved corners. I'm sure it
                    works great, but you can use the following to do the same:

                    function drawRect(penClip, xLoc, yLoc, wide, high, radius, fillColor,
                    fillAlpha) {
                    penClip.moveTo(xLoc, yLoc + radius);
                    penClip.beginFill(fillColor, fillAlpha);
                    penClip.curveTo(xLoc, yLoc, xLoc + radius, yLoc);
                    penClip.lineTo(xLoc + (wide - radius), yLoc);
                    penClip.curveTo(xLoc + wide, yLoc, xLoc + wide, yLoc + radius);
                    penClip.lineTo(xLoc + wide, yLoc + (high - radius));
                    penClip.curveTo(xLoc + wide, yLoc + high, xLoc + (wide - radius), yLoc +
                    high);
                    penClip.lineTo(xLoc + radius, yLoc + high);
                    penClip.curveTo(xLoc, yLoc + high, xLoc, yLoc + (high - radius));
                    penClip.lineTo(xLoc, yLoc + radius);
                    penClip.endFill();
                    }

                    You can set a lineStyle and no fill to do an outline rect as well... HTH

                    --
                    Dave -
                    Head Developer
                    www.blurredistinction.com
                    Adobe Community Expert
                    http://www.adobe.com/communities/experts/


                    • 7. Re: drawind API help
                      Peter Lorent Level 2
                      Here it goes: Good luck!
                      • 8. Re: drawind API help
                        Sketchsta Level 1
                        Hey DMennenoh, Thanx alot for the code, i just tried it, works great..

                        but heres the thing.. and I mean no offense... =)

                        But it's a good thing I cant understand your code, because i'm trying to write a code to draw rounded rectangles too..
                        I'm a script newbie, and this would be my verry first script i have ever made from scratch.. if i can get it to work that is. =)


                        I have one question tho:

                        var ctrl:Number="cWidth"+20;

                        is this possible anyother way to do?
                        because Flash tells me...Found string where Number is required.
                        • 9. Re: drawind API help
                          Level 7
                          var cWidth:Number = 10;
                          var ctrl:Number = cWidth + 20;

                          You need to leave out the quotes otherwise it is a string and not a number.

                          --
                          Dave -
                          Head Developer
                          www.blurredistinction.com
                          Adobe Community Expert
                          http://www.adobe.com/communities/experts/


                          • 10. Re: drawind API help
                            blemmo Level 1
                            cWidth seems to be a variable's name, so get rid of the quotation marks:
                            var ctrl:Number = cWidth + 20;

                            hth,
                            blemmo
                            • 11. Re: drawind API help
                              Sketchsta Level 1
                              kool, thanx guys
                              it works now.. =)