PDA

View Full Version : Root and and Parent issues for Simple Navigation Menu


bdavey311
08-06-2008, 10:11 PM
I have a Navigation Menu on my main timeline that then has the interactivity inside of that. When I click on a button I want it to go to the main timeline and gotoandPlay the respective label that I tell it to go to. Obviously a "root" and "parent" issue.

I looked around and I found something to the effect of using:

Code:

function onClickHandler(event:MouseEvent) {
MovieClip(this.parent.parent).gotoAndPlay("KnowledgePAGE");
}

Then I get the error message that says:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Stage@2d52f99 to flash.display.MovieClip.
at unityrings_fla::Menu_3/onClickHandler()

With that being said - Here is all the code:
Code:

stop();
import flash.display.MovieClip;
import flash.events.MouseEvent;

knowledgeMC.addEventListener(MouseEvent.ROLL_OVER, overHandler);
knowledgeMC.addEventListener(MouseEvent.ROLL_OUT, outHandler);
knowledgeMC.addEventListener(MouseEvent.CLICK, onClickHandler);

// if you want a hand cursor
knowledgeMC.buttonMode = true;
knowledgeMC.useHandCursor = true;

function overHandler(event:MouseEvent) {
knowledgeMC.gotoAndPlay("over");
}

function outHandler(event:MouseEvent) {
knowledgeMC.gotoAndPlay("out");
}

function onClickHandler(event:MouseEvent) {
MovieClip(this.parent.parent).gotoAndPlay("KnowledgePAGE");
}


AS3 is certainly not a walk in the park. I need a long learning session considering that I was just feeling comfortable with AS2.

Thanks in advance!
Brian

amarghosh
08-07-2008, 09:57 AM
if u have this code in document class, just use this
this.gotoAndPlay("KnowledgePAGE");
if its in some other class inside the main swf:
MovieClip(this.root).gotoAndPlay("KnowledgePAGE");
if the code is in a loaded swf, root will be different: in that case try this:
MovieClip(this.stage.getChildAt(0)).gotoAndPlay("KnowledgePAGE");

once u learn to walk, as3 is a walk in the park... everyone falls down while learning to walk :)