A lot of folks ask me how to create a simple preloader using ActionScript 3.0 in Flash CS3, so I thought I'd share the information with everyone all at once. Here's the idea behind creating the simple preloader shown here:
  1. Create necessary variables. You'll need the path to the file you want to load, in the form of a string. You need a URL request to represent the URL of the file, and you'll need an instance of the Loader class to load the file.
  2. Add event listeners to your Loader object's contentLoaderInfo property to listen for the Event.COMPLETE event (for when the file is done loading) and the ProgressEvent.PROGRESS event (to do stuff while the file is loading, or to show a preloader). You can learn more about the contentLoaderInfo property in Flash Help. Basically, it's the property that holds all of the information about the file that's loading, so you need to use it to register event listeners.
  3. Create event listener functions to respond to the events. Don't forget to put the loader on the stage using addChild() once it's loaded.
  4. In the ProgressEvent listener, you can access the loading info via the ProgressEvent's bytesLoaded and bytesTotal properties. Divide bytesLoaded by bytesTotal to calculate the percent that is loaded. The value will be between 0 and 1. Hold it in a variable for easy reference later on.
  5. To get a number that represents the percent loaded that is between 1 and 100, multiply the percent loaded variable by 100 and round the number using Math.ceil (so you don't get zero as a result).
  6. Use your rounded percent to refer to a movie clip frame to show when the file is at a particular percent. For example, once your file is 50% loaded, the preloader movie clip will display frame 50.
That's it! If you're not sure what these steps look like together in a completed file, you can download the source code here. Enjoy!

Note: I do not make any guarantee for these files regarding bugs or implementation in your applications. If you want to contact me to fix bugs or solve problems for your application, have your credit card number ready. =)
Amongst other cool happenings at the Budding Talent Night #2 for the LA Flash User Group, is Steven Sacks presentation on Gaia , the framework for building Flash sites uber-quickly.  I managed to get a run through last night and was really impressed.  I’ve talked, offered advice, and even contributed a tiny portion of sample [...]
In the previous articles in this series I explained how to create a horizontally and vertically resizable canvas. In this third article we will add the possibility to resize in both direction by dragging the right bottom corner. What we will do: add the new UI control (the right bottom button) create the necessary events for it create CSS [...]
Where I work we have these kind of workshops that are given by the employees. I was mandated to give a presentation entitled Advanced Flash, but it is not really going to be advanced; more like intermediate. I am basically going to introduce ActionScript 3, Tweening using TweenLite, Events, Linking symbol to a class, using [...]
Recently, I've been asked a lot about creating applications by writing code in an FLA file vs. creating them using classes and Object Oriented Programming. Making the decision can sometimes be tough, especially to those who are new to programming. Usually, it's hard for people new to programming to justify doing the work to create classes. Honestly, I use a lot of classes and FLA code. So, why choose either one when building an application?

OOP is a beautiful thing. Let me give an example of OOP in action. In order to create a music player using ActionScript 3.0, you need an instance of the Sound class to load and play the sound, an instance of the SoundChannel class to stop/pause/seek, and an instance of the SoundTransform class to control the sound's volume. Using OOP, I can make one class that connects all three. I could do that in an FLA file, but I'd have to rewrite or copy/paste the code every time, which takes time. Now, what if I wanted to add more functionality to every media player application I created? To do that, I'd have to add it to each FLA file. Using OOP, I simply update my EasySound class. Further, I can give my EasySound class methods that control all aspects of the sound (play,stop,pause,resume,seek,setVolume,etc.) and control the sound entirely from one instance. How cool is that!?

Pretty much the only thing that's not cool about OOP is that though OOP is better for reuse in the long run, it's initially more time consuming. For that reason, I'm not the biggest fan of document classes that I'm only going to use once.

At the same time, I'm a huge fan of making quick prototypes in FLA files. This enables me to rapidly create variables and functions for an app without having to create an entire class file. If I'm creating some sort of prototype, or teaching a programming idea, I prefer to go with an FLA and not create the class files.

The reason I stick to FLA files mostly for prototypes is because of the cons of using FLA files for major applications. One con is that FLA files don't contain searchable text, as ActionScript files do. Leveraging the power of my operating system (now Mac OS 10.5- whoot!), I can quickly search through thousands of class files to look for methods or comments that describe what the class does. Another con is reuse. Instead of redefining a function, or copying and pasting the function from one FLA to another, I simply import the class I created and run the method.

Moral of the story- I say to use FLA files for prototyping but to create classes for major applications, especially any applications where you would consider reusing code. If the time it takes to write code is an issue, you might want to consider writing code using Flex. Flex gives you case insensitive code hinting for everything, even your custom classes.

What methods do you use when creating applications? Do you prefer FLA or OOP?
I’ve been meaning to set this up for a while and finally I have a couple of classes in there. I’ll move all our publicly released stuff into this code library for ease of use over time, i.e. users will be able to get an email when me make updates or additions. http://code.google.com/p/tink/
Adobe released on the lab an early beta from Astro (Flash Player 10). This new player comes with some crazy new features like dynamic sound generation, new text engine, 3D, etc. As you can imagine, there is ONE feature I love : File Reference runtime access — Bring users into the experience by letting them load files [...]
Cool code by Chris Brimelow, showing the dropdowns being populated dynamically with data from an external xml file. The xml data is captured in multidimensional arrays and fed to the combobox components. When you select a make in the first dropdown it populates the model dropdown with the appropriate models. View Example and Download Source   [...]
For a few years now, I have been waiting for this: an official Google Maps Flash API (based on ActionScript 3). You heard it right, instead of using one of the many other solutions which tapped into the tiling servers of the various mapping providers, this is the real deal. And on the surface it [...]
It's not everyday I get to play around with API's but recently the opportunity arose from an insoluble grave. Get Flint kickin' it stated. Too much?
I put in my 2 weeks notice 3 weeks ago at Multicast Media Technologies, an Live and On Demand Online Video company here in Atlanta. I was originally hired as a Flex Consultant back in March of 2007. I had taken a 3 month sabbatical to find a product company that jived with [...]
Although is just one receipt I'm glad that my post was selected to be part of Flex 3 Cookbook. The original post can be found on Flex Cookbook Beta site by the name "Using More Themes in the same Application". The book release is in May but till now (13th of May 2008) it is still [...]

Really edge case here, but hey, it’s something. Background In creating a Vidego API (video content management API) example in Flash CS3, I ran into problems making an AS3 version from the AS2 version. Flash CS3 doesn’t haven an Accordion component, so I went about using a List instead. My problem with the List in [...]
Really edge case here, but hey, it’s something. Background In creating a Vidego API (video content management API) example in Flash CS3, I ran into problems making an AS3 version from the AS2 version. Flash CS3 doesn’t haven an Accordion component, so I went about using a List instead. My problem with the List in [...]
In this article I'll show the same application I presented at FlexCamp Bucharest Romania 2008 - the video from the conference is available here and although it is in Romanian it might be useful. In the presentation I'm showing the power of Flex: doing complex applications with a few lines of codding. With this article [...]
In ActionScript3 event driven programming plays a major part with mouse or key pressed and even a text field having events associated with them. Events indicate action e.g. mouse press corresponds to “mouse down” event and vice versa is “mouse up” event. To check if mouse release (mouseUp -Event.MOUSE_UP)) has happened on the target object on [...]
Since ActionScript3 is the core to Flash/Flex RIA it contains an expansive repertoire of display objects, graphical methods to create such applications. At the same time for design of such an application may need replication of same object several times. E.g. virtual pool table With AS3, in order to duplicate the properties of a Display object [...]
I was searching for a function to generate random Strings either in AS2 or in AS3 but I couldn't find any so I made my own using code from a typewriter effect, but I can't seem to find the page anymore. I use this code when I load dynamic content from php and such and [...]
In this post we will implement a login process with remember password functionality. In AS3 and also in AS2 we can use a SharedObject to store data on the users browser. Shared objects are similar to the all known browser cookies but are managed by the flash player. Shared objects can store data also remotely [...]
As most of us Flex or Flash developers are quite aware that the code we generate is often error prone; error handling is an issue that mandates serious consideration. While talking about errors we need to deal with compile time errors which are primarily due to syntax incorrectness along with run time errors that are [...]

Subscribe to Planet Flash

Search

Tags

<head> 3d 3d Flash Actionscript actionscript 3 ActionScript 3.0 Adobe Adobe Air Adobe AIR (Apollo) Adobe Flash Adobe Flex AdobeMAX08 AIR AIR Adobe Integrated Runtime Announcements apollo Art AS2 as3 Asides awards Babble BEA Beautiful Web Books Business Cairngorm ColdFusion Community Components Conference Conferences degrafa design dev Development Events Examples Featured Flash Flash CS3 Flash experiments flash player Flex Flex 3 Flex Builder Flex Builder Development Flex Example FMS Fun Gallery General GeoWeb Google Industry Inspiration iphone Jobs Links linux Marketing MAX MAX 2007 Misc News news & events Off topic Open Source Other Papervision3D Parallax Denigrate Personal photos Photoshop Process Processing Resources RIA Singularity Site News Stuff techmology Technology Tennis Thinking Loud Tips Uncategorized Video Whatever

Blogs

Buttons

Planetarium