A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Help me draw a dashed border?

  1. #1
    Member
    Join Date
    Aug 2003
    Posts
    30

    Help me draw a dashed border?

    Here's my latest attempt at rendering a dynamic rectange (w/ width, height, border_width, border_color & background_color) I'm trying to render a dashed border, and can't seem to get the code right...

    I've reworked my logic about five times, and can get the dashes to render right (almost) but the fill color disappears. It's rendered using actionscript. You can see the issues if you change the border width... Anyone mind taking a look to see what I'm doing wrong? It seems like the moveTo function isn't behaving right when I get to the end of each line. Thanks for any help!
    I've attached the .fla, here's my code:

    code:


    var w:Number = 300;
    var h:Number = 300;

    var border_width:Number = 6;
    var border_color:String = '0xcccc99';
    var background_color:String = '0x336699';
    var dash_width:Number = 10;
    var dash_space:Number = (border_width*3);

    // figure out how many horizontal dashes to render
    // this is crude, but tried other ways and still the fill isn't right...
    var h_num_dashes:Number = (w/(dash_width+dash_space));
    var v_num_dashes:Number = (h/(dash_width+dash_space));

    with(movBox) { // empty movie clip on the stage
    if(background_color) {
    beginFill(background_color,100);
    }
    lineStyle(border_width, border_color, 100 );
    // start
    moveTo(0,0);

    // top line
    //lineTo(w,0); // draws the next line without dashes for sanity's sake (debug)
    var xpos:Number = 0;
    for(i=0;i<h_num_dashes;i++) {
    lineTo((xpos+dash_width),0);
    moveTo((xpos+dash_width+dash_space),0);
    xpos += (dash_width+dash_space);
    }
    lineTo(w,0);

    // right line
    //lineTo(w,h);
    var ypos:Number = 0;
    for(i=0;i<v_num_dashes;i++) {
    lineTo(w,(ypos+dash_width));
    moveTo(w,(ypos+dash_width+dash_space));
    ypos += (dash_width+dash_space);
    }
    lineTo(w,h);

    // bottom line
    //lineTo(0,h);
    var xpos:Number = w;
    for(i=h_num_dashes;i>0;i--) {
    lineTo((xpos-dash_width),h);
    moveTo((xpos-dash_width-dash_space),h);
    xpos -= (dash_width+dash_space);
    }
    lineTo(0,h);

    // left line
    //lineTo(0,0);
    var ypos:Number = h;
    for(i=v_num_dashes;i>0;i--) {
    lineTo(0,(ypos-dash_width));
    moveTo(0,(ypos-dash_width-dash_space));
    ypos -= (dash_width+dash_space);
    }
    // finish
    lineTo(0,0);


    }


    Attached Files Attached Files

  2. #2
    half as fun, double the price senocular's Avatar
    Join Date
    Feb 2002
    Location
    San Francisco, CA (USA)
    Posts
    4,361

  3. #3
    Member
    Join Date
    Aug 2003
    Posts
    30
    Thanks again for solving another one!

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