display an object when clicking on another. I get Error 1009

  • Jose_M
  • Newbie
  • Newbie
  • Jose_M
  • Posts: 6
  • Loc: Malta

Post 3+ Months Ago

Hello!

I am trying to add some code to AS3 so that when the user clicks on an image (movie clip), another, which is hidden at that moment, appears on the screen.

This is what I have done so far on Actions frame:

Code: [ Select ]

import flash.display.MovieClip;
boton.buttonMode = true;
boton.addEventListener(MouseEvent.CLICK, clickPag13);
function clickPag13(event:MouseEvent):void {
  var minuevoMC:MovieClip = getChildByName('mymovieclip') as MovieClip;
  if (minuevoMC.visible == true) {minuevoMC.visible = false}
  else {minuevoMC.visible = true}
}
  1. import flash.display.MovieClip;
  2. boton.buttonMode = true;
  3. boton.addEventListener(MouseEvent.CLICK, clickPag13);
  4. function clickPag13(event:MouseEvent):void {
  5.   var minuevoMC:MovieClip = getChildByName('mymovieclip') as MovieClip;
  6.   if (minuevoMC.visible == true) {minuevoMC.visible = false}
  7.   else {minuevoMC.visible = true}
  8. }


where boton is the name of the movieclip the user has to click on,
and mymovieclip is the movieclip that will appear on the screen.

But it doesn't work.
I get the following Error in Output:


TypeError: Error #1009: No se puede acceder a una propiedad o a un m├ętodo de una referencia a un objeto nulo.
at flashworks_fla::MainTimeline/clickPag13()

which means something like the property or method of the reference of a null object can not be accessed at..



any idea, please, as to how can I solve this?

thank you and regards.
  • Jose_M
  • Newbie
  • Newbie
  • Jose_M
  • Posts: 6
  • Loc: Malta

Post 3+ Months Ago

Hi,

Problem solved.
I wasn't adding the new movieclip (mymovieclip) onto the Scene (invisibly), and that's why it wasn't beeing recognised.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.