A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Drawing box with ActionScript

  1. #1
    Junior Member
    Join Date
    Sep 2004
    Posts
    7

    Drawing box with ActionScript

    I am trying to draw a box with ActionScript at runtime, but cannot get it to work. Here is the code I am using. Does anyone know why it is not working?


    function drawBox(clip, color, alpha, lineType, x, y, w, h)
    {
    clip.lineStyle(lineType);
    clip.beginFill(color,alpha);
    clip.moveTo(x, y);
    clip.lineTo(x+w, y);
    clip.lineTo(x+w, y+h);
    clip.lineTo(x, y+h);
    clip.lineTo(x, y);
    clip.endFill();
    };


    var myMC = _root.createEmptyMovieClip("myClip",1);

    drawBox(myMC,0xDB3030,0xEEEEEE,1,20,30,100,30);

  2. #2
    Junior Member
    Join Date
    Sep 2004
    Posts
    7
    Okay, I figured out why my code is not working. The 'createEmptyMovieClip()' function is not returning a reference to the new movie clip. (Will this be fixed in the next version?) My work around code is listed below:

    function drawBox(clip, color, alpha, lineType, x, y, w, h)
    {
    clip.lineStyle(lineType);
    clip.beginFill(color,alpha);
    clip.moveTo(x, y);
    clip.lineTo(x+w, y);
    clip.lineTo(x+w, y+h);
    clip.lineTo(x, y+h);
    clip.lineTo(x, y);
    clip.endFill();
    };


    _root.createEmptyMovieClip("myClip",1);
    var myMC = _root["myClip"];
    drawBox(myMC,0xDB3030,0xEEEEEE,1,20,30,100,30);

    or

    drawBox(myClip,0xDB3030,0xEEEEEE,1,20,30,100,30);

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