Be a Supporter!

Use same variables?

  • 238 Views
  • 11 Replies
New Topic Respond to this Topic
IMACAT
IMACAT
  • Member since: Apr. 8, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Use same variables? Mar. 19th, 2013 @ 10:13 AM Reply

How can I use the same variables more than once in AS3?

For example I want to use the var 'number1' in multiple frames but I keep getting this error.

var number1:int = x

1151: A conflict exists with definition number1 in namespace internal.

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to Use same variables? Mar. 19th, 2013 @ 10:14 AM Reply

At 3/19/13 10:13 AM, IMACAT wrote: How can I use the same variables more than once in AS3?

For example I want to use the var 'number1' in multiple frames but I keep getting this error.

var number1:int = x

1151: A conflict exists with definition number1 in namespace internal.

number1 = x
you cant declare same variable more then one time


RangeError: Error #1125: The index 4 is out of range 4.

IMACAT
IMACAT
  • Member since: Apr. 8, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Use same variables? Mar. 19th, 2013 @ 12:20 PM Reply

At 3/19/13 10:14 AM, nitokov wrote:
At 3/19/13 10:13 AM, IMACAT wrote: How can I use the same variables more than once in AS3?

For example I want to use the var 'number1' in multiple frames but I keep getting this error.

var number1:int = x

1151: A conflict exists with definition number1 in namespace internal.
number1 = x
you cant declare same variable more then one time

Yes, but how do I use it more than once?

It's unnecessary to rewrite new variables that do the same thing on another frame.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Use same variables? Mar. 19th, 2013 @ 12:24 PM Reply

At 3/19/13 12:20 PM, IMACAT wrote: Yes, but how do I use it more than once?

It's unnecessary to rewrite new variables that do the same thing on another frame.

He just told you how.

Just use it. You don't have to redeclare.

IMACAT
IMACAT
  • Member since: Apr. 8, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Use same variables? Mar. 19th, 2013 @ 12:38 PM Reply

At 3/19/13 12:24 PM, 4urentertainment wrote:
At 3/19/13 12:20 PM, IMACAT wrote: Yes, but how do I use it more than once?

It's unnecessary to rewrite new variables that do the same thing on another frame.
He just told you how.

Just use it. You don't have to redeclare.

How would I go about using it? Do I just type number1, var number1:int ?

Every variable needs to be declared in any frame, this is why I'm asking the question.

nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to Use same variables? Mar. 19th, 2013 @ 01:13 PM Reply

1. Do you write code on timeline or in as class?
2. Is that AS2 or AS3?


RangeError: Error #1125: The index 4 is out of range 4.

IMACAT
IMACAT
  • Member since: Apr. 8, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Use same variables? Mar. 19th, 2013 @ 01:36 PM Reply

At 3/19/13 01:13 PM, nitokov wrote: 1. Do you write code on timeline or in as class?
2. Is that AS2 or AS3?

AS3 on timeline.

4urentertainment
4urentertainment
  • Member since: Aug. 1, 2008
  • Offline.
Forum Stats
Moderator
Level 13
Game Developer
Response to Use same variables? Mar. 19th, 2013 @ 02:30 PM Reply

At 3/19/13 12:38 PM, IMACAT wrote: Every variable needs to be declared in any frame, this is why I'm asking the question.

Where do you get this fact from?

You're refusing to try it. Just do it!

Frame 1:

var myVar:int = 0;

Frame 2:

myVar = 2;
trace(myVar);
MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Use same variables? Mar. 19th, 2013 @ 02:30 PM Reply

At 3/19/13 01:13 PM, nitokov wrote: 1. Do you write code on timeline or in as class?
2. Is that AS2 or AS3?

None of that matters.

var x:int = 5
x = 10
x = 15

Although you should be using AS3 in classes.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
IMACAT
IMACAT
  • Member since: Apr. 8, 2008
  • Offline.
Forum Stats
Member
Level 02
Blank Slate
Response to Use same variables? Mar. 19th, 2013 @ 05:44 PM Reply

At 3/19/13 02:30 PM, 4urentertainment wrote:
At 3/19/13 12:38 PM, IMACAT wrote: Every variable needs to be declared in any frame, this is why I'm asking the question.
Where do you get this fact from?

You're refusing to try it. Just do it!

Frame 1:

var myVar:int = 0;

Frame 2:

myVar = 2;
trace(myVar);

That's not exactly what I'm asking for. I'll try to rephrase it by using dynamic text.

First frame contains
var number:int = 1
hello_txt.text = number.toString()

Second frame contains
hello_txt.text = number.toString()

I want both txts on both frames to express the variable. But I need to state the variable every-time for this to work?

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to Use same variables? Mar. 19th, 2013 @ 11:26 PM Reply

Does the variable not exist on the second frame? I honestly wouldn't be surprised, no one will condone you using AS3 on the timeline, stick with classes.


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
nitokov
nitokov
  • Member since: May. 8, 2012
  • Offline.
Forum Stats
Member
Level 05
Programmer
Response to Use same variables? Mar. 20th, 2013 @ 04:48 AM Reply

I dont whant to demotivate you or something, but your way of doing this is very bad way. You cant cheat coding, there is no easier way, you can either do it good way or bad way, and this is school example of bad way. If you really whant to do something with AS3, please learn how to use classes when you start to learn it everything will become lot easier, and you will laugh at this problem, cheers


RangeError: Error #1125: The index 4 is out of range 4.