Skip to main content
Participant
January 8, 2013
Answered

How to make a document class visible through button click.

  • January 8, 2013
  • 1 reply
  • 885 views

package

{

          import flash.display.MovieClip;

          import flash.display.Sprite;

          import flash.events.MouseEvent;

          import flash.events.Event;

          import flash.display.Graphics;

 

          /**

           * ...

           * @7111211 Alex

           */

          public class Toggle extends MovieClip

          {

                    private var button:MovieClip;

                    private var button2:MovieClip;

                    public var myClock:AnalogueClock;

                    public function Toggle():void

          {

                    button = new MovieClip();

                    button.graphics.beginFill(0xFFCC00);

                    button.graphics.drawRect(0, 0, 80, 20);

                    button.graphics.endFill();

                    button.useHandCursor = true;

                    button.buttonMode = true;

                    button.mouseChildren = false;

 

                    button2 = new MovieClip();

                    button2.graphics.beginFill(0xCC0000);

                    button2.graphics.drawRect(0, 0, 80, 20);

                    button2.graphics.endFill();

                    button2.useHandCursor = true;

                    button2.buttonMode = true;

                    button2.mouseChildren = false;

 

                    button.addEventListener(MouseEvent.CLICK, buttonClickHandler);

                    button2.addEventListener(MouseEvent.CLICK, buttonClickHandler2);

 

                    this.addChild(button)

                    this.addChild(button2)

                    this.addChild(myClock)

          }

          public function buttonClickHandler(event:MouseEvent):void

          {

                    this.button.visible = false;

                    this.button2.visible = true;

                    this.myClock.visible = false;

          }

          private function buttonClickHandler2(event:MouseEvent):void

          {

                    this.button.visible = true;

                    this.button2.visible = false;

                    this.myClock.visible = true;

          }

          }

}

Comes up with an error saying the parameter child must be non-null, dont really know whats going on any help will be greatly appreciated

This topic has been closed for replies.
Correct answer kglad

line 52 is this.myClock.visible = true;

this.addChild(myClock); is in the public function part of the document.


myClock doesn't exist when line 52 executes.

1 reply

kglad
Community Expert
Community Expert
January 8, 2013

you're not going to make the document class visible via a button click but to find your error, click file>publish settings>swf and tick "permit debugging".  retest.

the problematic line number will be in the error message.  if it's not clear how to fix your error after seeing that, post the error message and indicate the problematic line of code.

Participant
January 8, 2013

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at Toggle/buttonClickHandler2()

I am not trying to make the document class appear, as i already do that in the main class file, i just want to hide it on button click, i take it i shouldn't include the addChild for myClock.

kglad
Community Expert
Community Expert
January 8, 2013

if:

this.addChild(myClock);

is line 52 in Toggle.as, then myClock doesn't exist when that line of code executes.