Seb Lee-Delisle


Mind your semi-colons!

(previously titled : Flash Player bug? for loops)

[UPDATE] Kudos and much thanks to Tim Knip who pointed out that it was in fact my mistake – there’s a stray semi-colon at the end of the line :

for each(byteArray in soundSources); 

Which is of course ending the loop there and just running the code in braces after that once. I seem to keep accidentally typing semi-colons lately. Perhaps it’s the frustration of having to work with the sound API. 🙂

And of course the good news is that we can safely continue to use for each…in. Yay! Thank you everyone for helping me find this.

I’ve been pulling my hair out over the last few days trying to get a sound toy working, don’t you hate it when you feel like you’re fighting against Flash? Anyway, I think I’ve found a bug, I’m iterating through an array of ByteArrays using for each, but for some reason it will only give me the last ByteArray.

I’m sure this has been the source of several unexpected behaviours in my current project. Can you let me know if it happens in your FlashPlayer? I’m currently running the debug player version

Here’s the swf :

[sorry, content no longer available]

And here’s what I see :

ByteArray bug 1

And here’s what I would expect to see :

ByteArray bug 2

You can see I’m iterating through the array twice, firstly with the iterator i and secondly with the for each directive.

And here’s the code :

	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.ByteArray;
	[SWF(width='200', height='150', backgroundColor='#000000', frameRate='30')]
	public class ByteArrayBug extends Sprite
		public var tf : TextField; 
		public var soundSources : Array; 

		public function ByteArrayBug()
			tf = new TextField(); 
			tf.height = 450; 
			tf.defaultTextFormat = new TextFormat("_sans", 11,0xffffff); 
			soundSources = [makeByteArray(), makeByteArray(), makeByteArray()]; 
			addEventListener(Event.ENTER_FRAME, enterFrame); 
		public function enterFrame(e : Event) : void
			tf.text = ""; 
			var count:int;
			var byteArray : ByteArray;
			for(var i : int = 0; i

Let me know what happens and your Flash Player version, and I'll pass it on to the relevant people. Thanks!

This entry was posted in Actionscript, Flash, Obsolete. Bookmark the permalink.

28 Responses to Mind your semi-colons!