Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 25th, 2011, 03:30 AM
Bglamb Bglamb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 2 Bglamb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 13 m 23 sec
Reputation Power: 0
[ActionScript 2] Variable not changing properly from within onPress

Hi there.

I'm very new to Flash, but I have been learning loads and getting some good results so far. Browsing these forums has been a massive help. However today I have hit a problem in what should be almost the simplest line of code I know how to write (variable = x), and could do with some advice.

I have a simple program containing a button which will change a variable when pressed. There is also a text-box that will output that variable. However when I press the button, the variable will change, but then immediately revert to it's previous value.


Code:
class Hero extends MovieClip
{
		
	var mmoloaded = "A"
		
	function onLoad()
	{
		_root.loadButton.onPress = function()
			{
			mmoloaded = "B"
			_root.mmoloadedText.text = mmoloaded
			}
	}
	
	function onEnterFrame()
	{						
		_root.mmoloadedText.text = mmoloaded			
	}
			
}


The effect is that when I press the button, it will change to "B" for a single frame, then back to "A".

I am writing all my code from within my 'Hero', and if I make the hero itself a button with the instance name 'heroButton' and put the code in there, then the code seems to work as intended. So is it something with the button just not being able to access the variables defined in the Hero class, despite being written inside the Hero class? I'm very confused!

Any and all advice is appreciated.

PS. I am using FLash CS3 and ActionScript 2.0

Reply With Quote
  #2  
Old May 25th, 2011, 09:23 AM
jamespayne's Avatar
jamespayne jamespayne is offline
Editor-in-Beef
Developer Shed Admin.
 
Join Date: Sep 2008
Location: South Florida
Posts: 328 jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level)jamespayne User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 5 Days 13 h 43 m 29 sec
Reputation Power: 10
Send a message via Yahoo to jamespayne
Test

Reply With Quote
  #3  
Old May 25th, 2011, 09:29 AM
eric miller eric miller is offline
Administrator
Developer Shed Admin.
 
Join Date: Jun 2010
Posts: 8 eric miller User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Week 20 h 13 m 7 sec
Reputation Power: 10
test

Reply With Quote
  #4  
Old May 25th, 2011, 09:31 AM
Bglamb Bglamb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2011
Posts: 2 Bglamb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 13 m 23 sec
Reputation Power: 0
Is it something to do with the scope of the variable?

Is it just changing a local variable while it's in the button function but not changing the real variable or something?

If the variable doesn't exist it will error, so I figured it must be changing the same variable. But I don't get why it would only change it for the duration of the button function.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > Variable changing but then resetting.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap