Sie sind nicht angemeldet.

Scott Witte

Fortgeschrittener

  • »Scott Witte« ist der Autor dieses Themas

Beiträge: 382

Wohnort: Milwaukee, WI USA

Beruf: Professional Photographer

  • Nachricht senden

1

Mittwoch, 1. April 2015, 06:39

Reusing variables the Copy action problems

Ran into a weird one in HTML5. Not sure if it is a bug or something I don't understand.

Apparently, if you set a variable to an array index it becomes strongly typed as a number? If you then try to set it to a string it results in NaN. But set it to another number and no problem.

But if you set the variable to a number it remains loosely typed and can then be set to a string no problem. Is this how it should work?

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
                set(test2, 'string');

		copy(test1, scene[get(xml.scene)].title );
		copy(test1, test2 );
		trace('TEST : ',get(test1) );  // TEST : string

		set(test1, 1 );
		copy(test1, test2 );
		trace('TEST : ',get(test1) );  // TEST : string

		copy(test1, scene[get(xml.scene)].index );
		copy(test1, test2  );
	 	trace('TEST : ',get(test1) );   // TEST : NaN

                set(test3, 3);
		copy(test1, scene[get(xml.scene)].index );
		copy(test1, test3  );
	 	trace('TEST : ',get(test1) );   // TEST : 3

NOTE: This is not how it works in Flash. instead of NaN in the above example it traces to TEST : string.

benji33

Fortgeschrittener

Beiträge: 244

Wohnort: France

Beruf: Senior Software engineer

  • Nachricht senden

2

Mittwoch, 1. April 2015, 09:06

Probably the "all is string" statement is used for Flash player.
Perhaps prefer the use of set rather than copy when changing the casting ?