A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Accessing instances on second frame

  1. #1
    Junior Member
    Join Date
    Mar 2009
    Posts
    8

    Question Accessing instances on second frame

    Hi,

    I can't seem to access instances in a movie clip that aren't on the first frame of a parent movie clip even if I tell flash to go to that frame before I attempt to reference the instance in the actionscript.

    Actually this works in flash player 10 but not 9. I could just export for flash player 10 but I would rather know the answer than just avoid it and of course for better compatibility reasons.

    I've attached an fla example with source code to show the problem. I'm using CS4 and programming in classes in as3 as you will be able to see from the example.

    Any help from anyone who knows how to do this properly would be greatly appreciated.

    Thanks.

    P.S: the example is saved in CS3 so more people can open it.

    Edit: Since there's not alot of code I'll paste it here for people to see.

    Code:
    package src
    {
    	import flash.display.MovieClip;
    	import flash.events.*;
    	
    	public class Main extends MovieClip
    	{
    		public function Main()
    		{
    			//Setting the beggining state
    			movieClipHolder.gotoAndStop(1);
    			
    			//The event Listeners
    			button.addEventListener(MouseEvent.CLICK, playAnimation);
    			addEventListener(Event.ENTER_FRAME, checkAnimation);
    		}
    		
    		private function playAnimation(e:Event)
    		{
    			movieClipHolder.gotoAndStop(2);
    		}
    
    		private function checkAnimation(e:Event)
    		{
    			if(movieClipHolder.currentFrame == 2)
    			{
    				if(movieClipHolder.animation.currentFrame == movieClipHolder.animation.totalFrames)
    				{
    					movieClipHolder.gotoAndStop(1);
    				}
    			}
    		}
    	}
    }
    Attached Files Attached Files
    Last edited by Nytrus; 06-13-2009 at 11:54 AM.

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    15
    Make sure the the reference is instantiated before it is called. This means that the script is run after the object is loaded.

  3. #3
    Junior Member
    Join Date
    Mar 2009
    Posts
    8
    Thanks for the reply but how would I do that exactly? I thought since the script that references it is only run after a button is pressed that it would have already loaded unless you press it really quickly. Or do you mean that I have to do something to make flash load the whole movie clip and not just the first frame?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center