How do you run loop functions on specific frames of nested Movieclips?
Webshark2000 Feb 4, 2010 6:26 AMI'm still pretty new to AS3 and I've run into a problem that I never had with AS2. I have a project where the 1st frame of the main timeline is the loading screen and the second frame has buttons and a title bar that I want to be on every "page" of my project. There are 7 buttons that take the user between 7 different "pages", which consist of 7 frames of a movieclip I have filling the content area on frame 2 of my main timeline. I'll call this movieclip "pages_mc".
The problem is that frame 6 of the pages_mc movieclip has the following code:
var moving = 0;
var xmoved;
var xbegin = pano_cont.pano_image.x;
parts_mc.addEventListener(Event.ENTER_FRAME, moveImage); // constantly moves the image 1 pixel left or right depending on the button pressed
btn_left.addEventListener(MouseEvent.MOUSE_DOWN, moveLeft); //changes the variable "moving" to 2 on mouse down
btn_right.addEventListener(MouseEvent.MOUSE_DOWN, moveRight); //changes the variable "moving" to 1 on mouse down
btn_left.addEventListener(MouseEvent.MOUSE_UP, stopMoveLeft); //changes the variable "moving" to 0 on mouse up
btn_right.addEventListener(MouseEvent.MOUSE_UP, stopMoveRight); //changes the variable "moving" to 0 on mouse up
function moveImage(e.Event):void{
xmoved = xbegin - pano_cont.pano_image.x;
if(moving == 1)
{
pano_cont.pano_image.x -= 1;
}
if(moving == 2)
{
pano_cont.pano_image.x += 1;
}
if(xmoved < -(pano_cont.pano_image.width/2)+180)
{
pano_cont.pano_image.x = -2538;
}
if(xmoved > (pano_cont.pano_image.width/2)- 180)
{
pano_cont.pano_image.x = -2178;
}
}
function moveRight (e:MouseEvent):void
{
btn_right.gotoAndStop("down");
moving = 1;
}
function moveLeft (e:MouseEvent):void
{
btn_left.gotoAndStop("down");
moving = 2;
}
function stopMoveLeft (e:MouseEvent):void
{
moving = 0;
btn_left.gotoAndStop("active");
}
function stopMoveRight (e:MouseEvent):void
{
moving = 0;
btn_right.gotoAndStop("active");
}
This is all just some code to allow users to move a panaromic image around on the screen. But when I navigate to a different page from of my pages_mc movieclip I get the following output message:
TypeError: Error #1099: Cannot access a property or method of a null object reference.
at SampleProject_fla::Content_MC_1/moveImage()
I'm thinking this is happening because the "parts_mc" movieclip I referenced for the ENTER_FRAME event listener no longer exists (unless you go back to frame 6 of pages_mc). I'm not sure how to remove this event listener when the user moves to another frame of pages_mc.
Any help would be greatly appreciated.



