;

PDA

Click to See Complete Forum and Search --> : Drawing box with ActionScript


d_dible
10-25-2004, 04:31 PM
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);

d_dible
10-25-2004, 05:30 PM
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);