Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to make a document class visible through button click.

New Here ,
Jan 08, 2013 Jan 08, 2013

package

{

          import flash.display.MovieClip;

          import flash.display.Sprite;

          import flash.events.MouseEvent;

          import flash.events.Event;

          import flash.display.Graphics;

 

          /**

           * ...

           * @author 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

TOPICS
ActionScript
823
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 08, 2013 Jan 08, 2013

myClock doesn't exist when line 52 executes.

Translate
Community Expert ,
Jan 08, 2013 Jan 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2013 Jan 08, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2013 Jan 08, 2013

if:

this.addChild(myClock);

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2013 Jan 08, 2013

line 52 is this.myClock.visible = true;

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 08, 2013 Jan 08, 2013

myClock doesn't exist when line 52 executes.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 09, 2013 Jan 09, 2013

Done it now, thanks.

Just a side question, i have made a digital clock, but i have coded in the text box, is there anyway for me to link a dynamic text box in the document class?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 09, 2013 Jan 09, 2013
LATEST

i'm not sure what you mean by "..i have coded in the text box.." but the document class can reference any object that exists at the time it's referenced.

if you have a textfield (eg, tf) on the main timeline, you can always use:

MovieClip(root).tf

to reference it unless your document class extends the sprite class in which case you use: 

Sprite(root).tf

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines