This article is a result of my experiences with streaming MP3 streams with AS3 on a ATOM-based device. After playing a stream for a given period of time the Flash Player kept crashing for no apparent reason. After some investigation I found a memory leak within my streaming application, and after further investigation I was able to narrow it down to the Sound class in AS3 (with good help from this blog post by Madarco). I quote:

“While you listen to an mp3 in streaming mode: snd.loadSound(url, true), flash will keep in memory the music played.”.

Now, when you have a continuous stream this means trouble. The memory used by the stream will not be released until the stream is closed.

Based on the info provided in Madarco’s post I spent some time working on a solution that would satisfy my needs. I ended up with an approach that initiates a second stream once the first has a buffer of a given size. Once the limit is reached I initiate the second stream at zero volume, then use GreenSock’s VolumePlugin tween to cross-fade the two streams. Once this is done, I free the memory reserved by the first stream and swap the references.

A complete working implementation can be found at PasteBin. For the sake of demonstration I’m swapping streams after 500kb, but this is clearly not an ideal limit for real world usage. This can also be tweaked to take the amount of used memory and / or time played instead of just looking at the buffer size when deciding when to swap streams. I still have quite some testing ahead before I feel comfortable using this, but it’s a good start. Hope this can help others faced with the same problem.

Book review: Papervision 3D Essentials (follow link to buy)
ISBN 1847195725
ISBN 13 978-1-847195-72-2
Publisher: Packt Publishing
Author: Paul Tondeur and Jeff Winder.
This review here is long overdue, but since work got a bit hectic, and I spent some time moving it got pushed back.

Papervision3D Essentials Cover

Papervision3D Essentials Cover

Short version: If you want to get started with Papervision 3D, get this book. It’s a well written, great introduction for people new to Papervision3D, as well as a good reference for more experienced developers. It covers everything from basics to filters, effects and performance topics.

Longer version: Before I started reading this book I had never used Pv3D except looking at some neat demos. I had some experience with OpenGL from way-back, so the basic 3d concepts were not new to me.  As I got started I found that most of what I knew from general 3d graphics development was covered pretty well in the first few chapters. From the basic building blocks, to coordinate systems and primitives. The book starts out with a chapter dedicated to setting up authoring tools for compiling the code created during the book. Both Flash CS3/CS4 and Flex/Flash Builder is covered. After that it deals briefly with some core AS3 concepts before moving on to fundamental 3D subjects. Everything is explained really well, and as the book progresses trough the rest of the chapters it details subjects as drawing primitives, adding materials, setting up cameras and loading external models, then going on with particle systems, external models, filters and effects. A chapter is also dedicated to performance optimization. The book offers a number of good examples, also available on-line.

The authors are clearly very comfortable with the subjects they are covering, and discussing pretty much every topic in a language that makes it easy to follow, also for less experienced developers. In my opinion this is a very well written book that I would not hesitate to recommend to beginning developers as well as experienced.

Book review: Flex 3 with Java (follow link to buy)
ISBN: 1847195342
ISBN: 13 978-1-847195-34-0
Publisher: Packt Publishing
Author: Satish Kore

Flex 3 with Java Cover

Flex 3 with Java Cover

Short version: If you are a Java / PHP developer seeking to get started with Flex, building on your skills as a server-side developer, this book will do you good. If you are new to software development, or just started out I would recommend you check out Essential ActionScript 3.0 by Colin Mook, then come back to this book when you have some experience doing applications with AS3.

Slightly longer version: Some time ago I reviewed Mastering phpMyAdmin 3.1 from Packt Publishing, and since they had some interesting books on Flash / Flex I volunteered to review a few more.
First out is Flex 3 with Java. It’s a 300 page book, dealing with Flex, Java and how you can build solutions using BlazeDS as a backend.
I first checked out Flex back when the Flex 3 beta came out. At that time I was doing PHP with the Prado Framework, and instantly felt like home within the Flex IDE. However, I never took the time to really get into Flex, and my knowledge of ActionScript was pretty limited at the time.
I’ve now been working with AS3 for six months, and I’ve got a pretty solid grip on it. Most of the work I’m doing is pure AS3 (no Flash IDE, no Flex SDK), but I’ve got some very interesting side-projects built on Flex in the works as well.

The book assumes you have no experience with Flex / Actionscript from earlier. Now, it is clearly written for a more tech-savvy audience. You do not need to be a experienced developer to follow the subjects covered, but it will most certainly help to have done some software development before picking it up. The author gets a bit ahead of himself on some topics in the book, but it’s not a big problem. However, I would have liked to see a “who is this book for” section at the beginning, stating that this books is well suited for developers wanting to pick up Flex.
As expected it spends the first few chapters dealing with installation on the Flex SDK / tools as well as a brief but good coverage of AS3 and the basics of MXML.

Going into this book I was expecting the majority of the contents to cover the actual interop between Java and Flex. The book clearly deals with much more than that. Given that I’ve been trough a number of Flex and AS3 books the last months I think I would have preferred a book that was focusing more of it’s energy on the core subject instead of peripheral topics such as styling, packaging and deployment and i18n support. I totally agree that these subjects are important to master, but I think it would have been better if the book focused more on the actual interops topics as mentioned above. For me the books falls a bit between two chairs, as it does not spend enough time on basics to give the complete beginner a deep enough intro to Flex and AS3, yet not enough on the heavier side for the more experienced developer.

Oh, the book is also available as PDF if you prefer that.

Download Chapter 5 – Working with XML

PS: Check back soon as I will have a review of Papervision3D Essentials ready!

Following my review of Mastering phpMyAdmin 3.1 Packt Publishing was kind enough to send me a couple of more books to review. While I am waiting for these books to get here I have gotten my hands on some sample chapters. Check them out!

Papervision3D Essentials

Papervision3D Essentials Cover

Papervision3D Essentials Cover


Authors
Jeff Winder, Paul Tondeur
ISBN
1847195725
ISBN 13: 978-1-847195-72-2

Download Chapter 8 – External models











Flex 3 with Java

Flex 3 with Java Cover

Flex 3 with Java Cover

Author Satish Kore
ISBN 1847195342
ISBN 13 978-1-847195-34-0

Download Chapter 5 – Working with XML