1

Currently I am trying to figure out code to add a movieclip to the stage after clicking an externally loaded image inside a movieclip.

Basically what I want to achieve is that when the external image that is loaded in the movieclip is clicked, another movieclip (a big X) is loaded on top of it. Currently I am trying this code, but the movieclip X doesn't show up. I don't get errors however.

Does anybody know how to resolve this? Thanks in advance!

Here's the current code:

var wronganswer1:Loader = new Loader();
var myImageLocation1:URLRequest = new URLRequest("Monthly Topic/img1.jpg");
var xClip:MovieClip = new MovieClip;

wronganswer1.load(myImageLocation1);
addChild(wronganswer1);

wronganswer1.addEventListener(MouseEvent.CLICK, wa1);

function wa1 (event:MouseEvent):void
{
    MovieClip(this.parent).SCORE -= 1   
    MovieClip(this.parent).addChild(xClip);
    wronganswer1.removeEventListener(MouseEvent.MOUSE_UP, wa1);
}

stop();
ECcoding
  • 45
  • 6

1 Answers1

1

Your xClip does not contain any graphics, it is just an empty MovieClip instance:

var xClip:MovieClip = new MovieClip;

So it is added to the appointed target as intended, you just can't see it because there's nothing to see.

Organis
  • 7,243
  • 2
  • 12
  • 14
  • Thanks for responding! I am not sure I understand what you mean or how to solve it. The movieclip does contain graphics, namely a big red X. Or do you mean that the way I set it up I set it up is as an empty movieclip? – ECcoding Jun 20 '17 at 01:13
  • Okay I figured it out! I now get what you mean. I ended up using var xclip:MovieClip = new xClip; That worked perfectly! Thanks for the help! – ECcoding Jun 20 '17 at 01:44
  • 1
    @ECcoding Good. As a side note, I advise against using same or even similar names for classes and their instances, it can lead to unwanted trouble. Naming like **var xclip:MovieClip = new BigX;** would be much better. – Organis Jun 20 '17 at 09:45
  • Thanks for the suggestion! I'll make sure to keep that in mind! – ECcoding Jun 21 '17 at 06:12