2
votes

I have a map consisting of MovieClip cities inside it and I have a click function in top layer of map MovieClip. I try to do that if I click a city, a rectangle will be drawn. Here is code:

function rpress(a)
{
trace( "trying" );

    var b:MovieClip = new MovieClip();
    b.graphics.beginFill(0xFF0000);
    b.graphics.drawRect(0,0,100,80);
    b.graphics.endFill();
    b.x = 150;
    b.y = 150;
    addChild( b );
trace("done")
}

Trace commands are executed but no rectangle is drawn. I tried MovieClip( root ).addChild..., stage.addChild..., MovieClip( parent ).addChild... and others...

Do you have any idea? Thank you!

FULL CODE:

Double Click map MovieClip->84 layers welcome us->Chose the layer named "Action Layer" ACTIONS-FRAME:

function rbtxt(a)
{
    var _loc2 = a;
    var _loc3 = this;
    balon._visible = true;
    arbtxt = ilad.split(",");
    balon.txt.text = arbtxt[_loc2];
    _loc3["x" + _loc2].play();
    balon._x = _loc3["x" + _loc2]._x;
    balon._y = _loc3["x" + _loc2]._y - _loc3["x" + _loc2]._height / 2 + 5;
}
//End of the function
function rbalon(a)
{
    balon._visible = false;
    this["x" + a].gotoAndStop(1);
}
//End of the function
function rpress(a)
{
trace( "trying" );

    var b:MovieClip = new MovieClip();
    b.graphics.beginFill(0xFF0000);
    b.graphics.drawRect(0,0,100,80);
    b.graphics.endFill();
    b.x = 150;
    b.y = 150;
    addChild(b );
trace("done")
}

ilad = "CITY NAMES....."
ilurl = "CITY URLS....."
3
Sprite but how? Like var b:Sprite = new Sprite(); ? If you meaned that it doesn't work... It gives " 'Sprite' could not be loaded " error. - ciyo
Can you post your .fla or full code? You're rpress() function looks fine, so it must be something else. - BadFeelingAboutThis
Okey, I will edit my post now. - ciyo
Still don't have much context, how is rpress() called? You said you tried stage.addChild(b) and still didn't see the rectangle? How do you get rid of the rectangle later? - BadFeelingAboutThis
rpress() is called when you click a city MovieClip as on (release) { _parent.rpress(a); } - ciyo

3 Answers

1
votes

You are not showing enough code, so we can only guess. By looking at the info you supplied you could try:

this["x" + a].addChild( b );

or

balon.addChild( b );

But this is only guessing...

1
votes

Hi try to add the movie clip to the stage and then execute the drawing camamnd like this

 var b:MovieClip = new MovieClip();
    addChild(b );
    b.graphics.beginFill(0xFF0000);
    b.graphics.drawRect(0,0,100,80);
    b.graphics.endFill();
    b.x = 150;
    b.y = 150;
0
votes

Sprite has access to graphics, try and only use Movieclip for complex objects such as SWFs loaded in and Flash library assets with timeline based animation and variables etc

function drawRect()
{
    trace( "trying" );

    //var b:MovieClip = new MovieClip();
    var b:Sprite = new Sprite();
    b.graphics.beginFill(0xFF0000);
    b.graphics.drawRect(0,0,100,80);
    b.graphics.endFill();
    b.x = 150;
    b.y = 150;
    addChild( b );
    trace("done")
}