2

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....."
ciyo
  • 725
  • 4
  • 16
  • 36

3 Answers3

1

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...

sanchez
  • 4,519
  • 3
  • 23
  • 53
1

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;
Khaled Garbaya
  • 1,479
  • 16
  • 20
0

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")
}
Darcey
  • 1,949
  • 1
  • 13
  • 22
  • To be even more minimalistic and lightweight we could use the Shape class. Btw. I don't know why you got down voted, because it is a good point, anyway it wasn't me, I would need 150 reputation to be able to be that cruel ;) – sanchez Aug 03 '12 at 23:21
  • Shape class would be most efficient... this isn't an answer to the question though and would be more appropriate in the comments. – BadFeelingAboutThis Aug 07 '12 at 21:19
  • Im not here to do other peoples jobs for them but point them in the right direction. I will just post links to adobe live docs from now on. People geez. – Darcey Aug 08 '12 at 01:06