A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: changing border of a square

  1. #1
    Senior Member
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    166

    changing border of a square

    Lets say I have a square like this:

    var square:Sprite;
    square = new Sprite();
    square.graphics.lineStyle(3,0xffffff);
    square.graphics.beginFill(0x000000,0);
    square.graphics.drawRoundRect(0,0,100,100,20);
    square.graphics.endFill();
    How can I change the color of the border (i.e lineStyle) from 0xffffff to 0x000000 at runtime, so if a user clicks a button the color of the border changes from black to white.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Once it is drawn, you cannot change it. You could clear square's graphics and redraw with the new color.
    You could even create a vector of IGraphicsDatas representing each of these drawing steps and replace the color in one of them, then replay the drawing using drawGraphicsData. But that's probably overkill. Just make a function to draw the square and pass the color in.

  3. #3
    Senior Member
    Join Date
    Mar 2003
    Location
    Canada
    Posts
    166
    one question about flash, when we use a variable name like square which is a sprite we reassign a new sprite

    function sqaureIt(){
    square = new Sprite();
    square.graphics.lineStyle(3,0xffffff);
    square.graphics.beginFill(0x000000,0);
    square.graphics.drawRoundRect(0,0,100,100,20);
    square.graphics.endFill();
    }
    Does flash automatically remove the previous sprite from memory? If not whats the best way to go about this?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    If there are no more references to the old item, it will be eligible for garbage collection. This means it is not on the display list, has no non-weak listeners, and nothing else has a reference to it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center