Seb Lee-Delisle

Menu

Mind your semi-colons!

(previously titled : Flash Player bug? for each..in 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 10.1.51.82.

Here’s the swf :

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 :

package
{
	import flash.display.Sprite;
	import flash.events.Event;
	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); 
			addChild(tf);
 
			soundSources = [makeByteArray(), makeByteArray(), makeByteArray()]; 
 
			addEventListener(Event.ENTER_FRAME, enterFrame); 
 
		}
 
		public function enterFrame(e : Event) : void
		{
			tf.text = ""; 
 
			var count:int;
			var byteArray : ByteArray;
 
			count=0; 
 
 
			for(var i : int = 0; i<soundSources.length; i++)
			{
				byteArray = soundSources[i] as ByteArray; 
 
				tf.appendText(count+" "+byteArray.length+ " "+soundSources.length+"\n"); 
 
				count++; 
			}
 
			tf.appendText("-------\n"); 
 
			count = 0;
 
			for each(byteArray in soundSources); 
			{
 
				tf.appendText(count+" "+byteArray.length+ " "+soundSources.length+"\n"); 
 
				count++; 
			}
 
		}
 
		public function makeByteArray() : ByteArray
		{
			var ba : ByteArray = new ByteArray(); 
 
			for(var i : int = 0; i< 100 ; i++)
			{
				ba.writeFloat(0); 
			}
			return ba; 
		}
 
 
	}
}

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. Bookmark the permalink.

28 Responses to Mind your semi-colons!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current day month ye@r *