PDA

View Full Version : AS3 movieclip navigation



dlinville
January 30th, 2009, 02:04 PM
Hello, I know this is probably simple for most actionscripters...

Im trying to create movieclip navigation...meaning..when you click on one mc, it play's it's "in" labeled frame...and it will play the "out" labeled frame when another movieclip is pressed. Here is my non-working code.

var activeRegion;

function getwest (event:MouseEvent):void{
if ( activeRegion != mcWest ){
activeRegion.gotoAndPlay("out");
mcWest.gotoAndPlay("in");
activeRegion = mcWest;
}
}
mcWest.addEventListener(MouseEvent.CLICK, getwest) ;

function getMidwest (event:MouseEvent):void{
if ( activeRegion != mcMidwest ){
activeRegion.gotoAndPlay("out");
mcMidwest.gotoAndPlay("in");
activeRegion = mcMidwest;
}
}
mcMidwest.addEventListener(MouseEvent.CLICK, getMidwest) ;

mpelland
January 30th, 2009, 03:19 PM
it is possible that it is related to an issue with the playhead going too fast in AS3

check out this library that a friend of mine made. look through the examples for some help and the description to see if it will help with the problem

http://code.google.com/p/as3-display-list-library/

cbeech
January 30th, 2009, 03:24 PM
it appears that at this time there is no value(mc) assigned to 'activeRegion' - you should provide a 'default' value for the variable. looks like your probably getting a 1009 error? null object reference - because of the line: activeRegion.gotoAndPlay('out');

edit: sorry mpelland - i was typing previous to seeing your post here :)

dlinville
January 30th, 2009, 04:12 PM
it appears that at this time there is no value(mc) assigned to 'activeRegion' - you should provide a 'default' value for the variable. looks like your probably getting a 1009 error? null object reference - because of the line: activeRegion.gotoAndPlay('out');

edit: sorry mpelland - i was typing previous to seeing your post here :)

Thank you for your replies,

ok, I entered applied a value, below is my script...and now I get the follow error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at states_fla::mc_nav_1/getwest()


var activeRegion:MovieClip;

function getwest(event:MouseEvent):void{
if (mcWest != activeRegion){
activeRegion.gotoAndPlay("out");
mcWest.gotoAndPlay("in");
mcWest = activeRegion;
}
}
mcWest.addEventListener(MouseEvent.CLICK, getwest) ;

function getMidwest(event:MouseEvent):void{
if (mcMidwest != activeRegion){
activeRegion.gotoAndPlay("out");
mcMidwest.gotoAndPlay("in");
mcMidwest = activeRegion;
}
}
mcMidwest.addEventListener(MouseEvent.CLICK, getMidwest) ;

cbeech
January 30th, 2009, 05:57 PM
ahh see now you're getting somewhere - but you've given the variable a 'data type' but not a 'value' - you need to decide which 'region' appears on the stage by default and assign that clip to the instance initially.