Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-25-2012, 02:07 PM   #1
Registered User
Join Date: Jun 2012
Posts: 1
Default [AS3] Switching frame by variable - character select

Hi all,
I'm currently working on a game based on the avoider game series written by Micheal James Williams.
It has taught me to make use of multiple scripts. The game is almost to my liking except for one thing. I'm trying to include a character selection in the menu screen.

My plan on how to do this was to include a button in the start screen, that sends out a global variable that will later be used in the avatar MC to select either frame one or two, depending on which was chosen. But I'm allready stuck at reading out the variable.

I'm currently working with a test set up that just provides the variable, and combines a function to it. But for some reason it's not working.

Avatar.as is linked to my avatar movieclip, this movieclip contains two frames, one labeled frame1 and the other labeled frame2.

I've got the following code in my Avatar.as.

public var button = "2nd";
And at the bottom.

public function frameChange() :void
         if (button == "2nd"){
         trace("Var read");
I get no errors, and no trace that the var has been read.

Any help would be greatly appreciated.
pafke is offline   Reply With Quote
Old 06-25-2012, 07:08 PM   #2
Registered User
Join Date: Jun 2012
Location: USA
Posts: 27
Send a message via Yahoo to CodeVisual

I'm not sure why you're code is not executing. However I believe I know a better approach to this.

private var currentFrameNum:int = 1;
public function changeFrame(num:int)
     trace("Changing to frame " + num);
     currentFrameNum = num;
Then just call the changeFrame() from the document class and pass in the parameter to specify the frame.

This is basically how you set it up, but I think the best approach (if I understand your logic correctly) would just be changing the frame of the MovieClip in question. Then later on in your class you can use the "currentFrame" or "currentFrameLabel" properties to find out the current frame.
CodeVisual is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 01:51 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.