Archive for the 'ActionScript 2.0' Category

How to Jump Randomly to Frame Labels without Repeats

Wednesday, May 30th, 2007
Flash ActionScript 2.0

One of the more popular entries of this blog describes How to Jump to a Random Frame Label.  The ActionScript 2.0 involved is very straightforward, weighing in at a mere 5 lines.  Its sole purpose is to choose a random label once at the beginning, then go to it (then stop).  In the Comments section, a visitor named Heather asked for a variation in which the movie starts at a random label, then proceeds to the remaining labels in order, looping around to the beginning, if necessary, to hit each label once.  I offered some suggested code, and eventually a number of other visitors asked for yet another variation:  how to jump randomly to a whole series of labels — without repeats.  That takes a bit more code, but it’s certainly doable.  Let’s take a look.  Keep reading »

How to Pan the Audio in an FLVPlayback Video

Tuesday, May 1st, 2007
Flash ActionScript 2.0

This one came to me in a flash (ha ha … Flash!), thanks to a friendly discussion I had the other day with site visitor Michael Lokner.  He was wondering if it was possible to pan the audio portion of an FLV file in cases where the video is played in an instance of the FLVPlayback Component.  In another recent article, I explained how to use the MovieClip.attachAudio() method to control NetStream-based video, but that’s a different ball of wax.  The FLVPlayback Component has its own volume property, and even skins that feature a volume slider, but what about panning?  After bouncing ideas back and forth, Michael and I arrived at a simple answer.  Keep reading »

How to Adjust the Audio Portion of Flash Video

Tuesday, April 17th, 2007
Flash ActionScript 2.0

If you’re not using the FLVPlayback Component, or one of the older Media Components, then the audio portion of video files may have you scratching your head.  The Components have their own volume sliders, which makes volume control a snap, but what about panning (left to right fading), or what if you’re not using Components for video?  In ActionScript 2.0, video sound is a bit … well, it’s a bit odd, but once you understand it, audio control isn’t hard.  Keep reading »

How to Play Sound Files Sequentially

Friday, April 13th, 2007
Flash ActionScript 2.0

Many people use Flash to play background music on their site.  It’s a good use for Flash, especially if the audio is loaded from external MP3s, which keeps the SWF file size low, and if you give your visitors a way to toggle off the sound.  But one song may not be enough.  You may want to play a list of files one after the other.  If so, the next question is, “How easy is that?”  The answer is, “Very.”  Let’s take a look.  Keep reading »

How to Round to the Nearest Ten, Tenth, Hundred, Hundredth, Etc.

Friday, April 6th, 2007
ActionScript 2.0 Quick Tips

I was helping a friend the other day with a rounding issue.  He needed to round numbers not to the nearest integer, but to the nearest hundred.  So 52.3 would round to 100.  86 would round to 100 as well.  13 would round to 0 and 101.287 would round to 100.  You get the idea.  The Math.round() method doesn’t take any parameters except the to-be-rounded value itself, so how could this be accomplished?  The answer couldn’t be simpler.  Keep reading »

How to Determine the Completion of a Flash Video (FLV) File (AS2)

Monday, April 2nd, 2007
ActionScript 2.0

Nearly a year ago, I posted a short entry on Flash video, “How to Load External Video (FLV).”  As of today, that article has received more feedback than any other on this blog, often asking how to tell when a video file has completed.  The article describes a technique for loading external FLV files without the use of either the FLVPlayback Component or the older Media Components.  Looking back, I believe I should have referenced that detail somehow in the title, because many of the questions have ended up pertaining to FLVPlayback, which has its own complete event.  If you’re using that Component, handling the built-in event is the easiest way to respond to the end of a Flash video, and we’ll cover that in just a moment.  In the spirit of the original article, however, we’ll also take a look at how to determine the completion of a Flash video loaded with ActionScript and a Video object only.  Keep reading »

Loading and Tracking Multiple Files at the Same Time (Part 2)

Friday, March 16th, 2007
ActionScript 2.0

Three weeks ago, I started a two-part series on using a MovieClipLoader instance in a custom class to track the loading of multiple external files at the same time. When we left off, our custom MultiLoader class was complete enough to provide a decent amount of convenience:  an addClip() method managed a specified external file, a target movie clip, and arbitrary event handlers; a loadClips() method set the mass download in motion.  In the final paragraph, I said I’d follow up with a way to report the total group load progress.  This is that follow-up.  Keep reading »

Dude, Where Do I Put My Code?

Thursday, March 8th, 2007
Flash ActionScript 2.0

One of the recurring issues I see on the Adobe forums involves the “Statement must appear within on/onClipEvent handler” error, which is a baffling message if you don’t how what on or onClipEvent are — all the more so because, often as not, neither of those functions is necessary, as no events are being handled:  it’s just that the ActionScript has been typed or pasted into the wrong place.  I started a new series on Community MX that I hope will address this issue.  The first article is free.

http://www.communitymx.com/content/article.cfm?cid=C5F00

Note, this is specifically an overview.  It doesn’t go into ActionScript syntax in any great detail — it’s not a how-to-program tutorial — but it should give newcomers a better understanding of the placement choices they have when experimenting with code.

The VideoPlayer Class API (aka, the Missing Manual)

Tuesday, February 27th, 2007
ActionScript 2.0 Quick Tips

I was just gabbing with someone about the NetStream class, which nudged my mind toward the VideoPlayer class.  According to the Components Language Reference, the FLVPlayback class “extends the MovieClip class and wraps a VideoPlayer object.”  As it turns out, the VideoPlayer class is mentioned in the Components Langauge Reference, but if you dig into it, you’ll quickly discover that none of the class members is hyperlinked.  In other words, you’ll get an overview of the properties, methods, and events defined by that class, but no actual explanation.

I find that an odd omission — but Adobe does make the full API available.  Keep reading »

Loading and Tracking Multiple Files at the Same Time (Part 1)

Sunday, February 25th, 2007
ActionScript 2.0

Not long ago, a blog guest entered into conversation with me about loading and tracking multiple files at the same time (see Event Handlers versus Event Listeners comments, starting with the eighth comment).  Tiemen was hoping for a way to use the MovieClipLoader class inside a custom ActionScript 2.0 class, not only to load external files — which isn’t especially difficult — but also to track each file individually; that is, to be able to pass individual functions into the custom class, and have that class manage the tedium of assigning the passed-in functions to the MovieClipLoader events of each file.  This particular requirement was the tricky part.  If the custom class merely had to manage event handlers for a single MovieClipLoader instance, that would be easy.  (In fact, this is completely possible.  Be aware, if you choose to read the other entry’s comments, I mistakenly believed at the time that the events of a single MovieClipLoader instance were not capable of providing useful information for more than one loading file at a time.  I’ve noted those errors in my replies.)  Because Tiemen wanted the ability to assign separate functions for each file’s events, well … that meant maintaining an array of MovieClipLoader instances.  Let’s take a look at one way to accomplish this goal.  Keep reading »