Copy link to clipboard
Copied
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
myClock doesn't exist when line 52 executes.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
if:
this.addChild(myClock);
is line 52 in Toggle.as, then myClock doesn't exist when that line of code executes.
Copy link to clipboard
Copied
line 52 is this.myClock.visible = true;
this.addChild(myClock); is in the public function part of the document.
Copy link to clipboard
Copied
myClock doesn't exist when line 52 executes.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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
Find more inspiration, events, and resources on the new Adobe Community
Explore Now