August 2003 Archives

SharpFlash.. on SourceForge!!

| No Comments

The pre-alpha release of SharpFlash is now available!! I submitted a project request for SharpFlash early this week, and it was approved. I haven't uploaded the source to their CVS server yet, but that will be coming eventually. For now, the source code is available to download as part of the package.

The project is released under the GNU GPL, so please help out if you feel motivated. I've been doing all the work for this in my free time (hence the slow goings) and I could really use some community help with building out the ActionScript API. If you take a look at the source, you'll see that it won't be too hard to add features.

I'm very excited to finally show the community what I've been working on. Check out the 2 examples, and run the executables to see some of what SharpFlash can do. I just finished up the MessageBox example the other night, and gave Jesse a sneak preview. He responded with "Very phat!" so hey.. that means you should check it out as well.

There is a README.txt file in the main .zip archive as well. Please read that completely before attempting to do anything else with the program.

Also, bookmark these 2 URLs:
http://sharpflash.sourceforge.net (no content there yet, I hope to get that updated by tonight)
.. and the project page can be found here:
http://sourceforge.net/projects/sharpflash/

Visit the project page to download the files. Check it out, and let me know what you think! If you want to get involved, drop me an email. My e-mail address is in the README.txt file. I appreciate all of your comments..

dateFormat ActionScript port

| 9 Comments

Coming from a ColdFusion background (before I started using Flash) I used to take advantage of the DateFormat function. I've always wondered why there was never a Flash version. Well.. now there is! I'm actually surprised I haven't seen this function created before.

Click here to download my ActionScript version of ColdFusion's DateFormat function. Some example usages:

#include "dateFormat.as"

testDate = new Date(2003, 7, 9);
trace(dateFormat(testDate, "mmm-dd-yyyy"));
trace(dateFormat(testDate, "mmmm d, yyyy"));
trace(dateFormat(testDate, "mm/dd/yyyy"));
trace(dateFormat(testDate, "d-mmm-yyyy"));   
trace(dateFormat(testDate, "ddd, mmmm dd, yyyy"));
trace(dateFormat(testDate, "short"));
trace(dateFormat(testDate, "medium"));
trace(dateFormat(testDate, "long"));
trace(dateFormat(testDate, "full"));

Diamonds.. mass produced in factories.

| No Comments

It looks like we're going to see diamonds running computers.. perhaps sooner than you may think. Heres an interesting wired article about the New Diamond Age.

http://www.wired.com/wired/archive/11.09/diamond.html

Password Generation in C#

| No Comments

As promised, I've re-written the Password Generation example in C#. You can find the zip file here. Included in the download are the executable, the PasswordGenerator class, and the UI class.

By comparing all three versions of roughly the same class, you can see just how similar the languages are. The major differences in the C# version are how the random characters are generated and the use of delegates to store function references. This is a little cleaner and easier to follow than the Java counterpart or creating an interface with class wrappers.

I hope you learn something from these 3 examples, or at the very least get motivated to try learning a new programming language. It's not as hard as you may think to "hit the ground running," as they say. The more advanced topics obviously take some time, but once you get familiar with one language it should be relatively easy to pick up another one..

Good luck!

Password Generation in Java

| 6 Comments

Like my previous entry, this is the Password Generator again, but this time it's written in Java. It's is roughly the same PasswordGenerator class, but with the Java twist applied. I thought this would be a good illustration to show some of the similarities and differences of Java and ActionScript.

One of the biggest differences is trying to create the array of function references. You'll see that I had to make an interface and wrapper classes to make the generatePassword method look roughly the same as it's ActionScript equivalent. Additionally, I made use of Java's exceptions to make the PasswordGenerator class a little more robust.

There isn't a robust UI for this one - just the Java class and a Test class to show example usage. This probably isn't the "final" version of this Java class either. I'll probably continue to build on it, and eventually I'd like to release a GUI for it as well.. but again, there's only so much time in a day.

Download the Java implementation of my PasswordGenerator class here.

Note that you can use createObject in ColdFusion to use this Java class in your ColdFusion web apps, if you want.

And yes, you guessed it, a C# version will be coming on Sunday.

Password Generation in Flash MX

| No Comments

This little app grew out of necessity. I got tired of creating passwords, so I made a Flash app to create them for me. Source code available at the bottom.

You can find the source .fla file here. The code isn't very well commented, but it should be pretty straightforward. E-mail me if you need help with anything, and I'll update the file with better documentation then.

SharpFlash, back in the mix

| No Comments

Now that I've completed some things I've been meaning to do, I can pick up development of SharpFlash again. For those that haven't been following my weblog, SharpFlash is a project of mine that falls into the "third party Flash projector" category. It's written in C#, and of course has a Flash user interface. See here, here and here for more information.

Originally, I had written a socket server to comminicate from the C# wrapper to the Flash application. This was because I did not want to sacrifice the callback model that I have already implemented and I wanted to be backwards compatible with as many previous versions of Flash as possible. However, with Flash 7 looming around the corner and given the penetration of Flash 6... I'm going to ditch the socket server for a different approach. With the object.watch functionality I will be able to fire an event inside the Flash player just like the onData event of the socket server that I'm currently using. The plus is that the applications will run faster as they will no longer be multi-threaded. The downside is that you'll only be able to build Flash 6+ projects with it. Sorry to everyone still developing in Flash 5... hopefully there aren't too many of you left.

I'll keep posting status updates this week. I'm really going to try to get something "releasable" by the end of this week as it looks like I'll have a decent amount of development time available.

After I release a very alpha version with a not-even-close-to-being-complete feature set, I'll take all the help I can get in building out the libraries. Eventually I'll get around to releasing a sourceforge project, espeically if more people want to get involved, but I want to make a little more progress first...

Stay tuned...

Preloading into levels

| 11 Comments

I ran into something recently that I've never come across before when dealing with preloading content onto a level in Flash MX. You can't reference a level that has no loaded content, thus making it impossible to preload with meaningful messages (% loaded, bytes loaded, etc).

I've always managed my loading assests with depths and run preloaders calling getBytesLoaded and getBytesTotal on the "containter" movieclip that the content is being loaded into. A quick code example is in order.

function waitForLoad() {
	// the target loading movie clip is referenced
	// by the "ref_mc" variable
	bytesLoaded = this.ref_mc.getBytesLoaded();
	bytesTotal = this.ref_mc.getBytesTotal();
	percent = Math.floor(bytesLoaded/bytesTotal * 100);

	if (bytesLoaded == bytesTotal && bytesTotal > 4) {
		trace("done loading");
		// implicitly deletes the onEnterFrame loop when
		// the movie clip is removed
		this.removeMovieClip();
	}
}

// create a holder movie clip toload the external content into
createEmptyMovieClip("img_mc", 1);

// create a temporary movieclip to attach the frame loop 
// to which checks for the loading progress of the 
// movie clip referred to by "ref_mc"
createEmptyMovieClip("load_img_mc", 10);
load_img_mc.ref_mc = img_mc;

// assign the frame loop to be the preload function
load_img_mc.onEnterFrame = waitForLoad;

// load the external content
img_mc.loadMovie("external.swf");

I've never had an issue with code like this. However, if you want to use levels to load content into instead of depths (switch the loadMovie to loadMovieNum), the following code won't work:

trace(_level4.getBytesLoaded()); 
// "undefined", instead of an integer

However, once a .swf is loaded into a level, then the above code will return an integer value. It seems as though the _level reference only exists after the load is complete. I'm not sure that I understand why, and I didn't test any of this with the new Flash Player 7 beta floating around...

Still though, you can preloaded content into levels, but you can't report back loaded status. The preload code is actually a little easier... it would look like this:

function preloadLevel() {
   if (_level5 != undefined) {
      trace("level 5 loaded");
      delete this.onEnterFrame;
  }
}
_root.onEnterFrame = preloadLevel;
loadMovieNum("external.swf", 5); // load something into level 5

This isn't a bug - it works as described (from the Flash Reference). "Once a movie is loaded into a level, you can use the syntax, _levelN, where N is the level number, to target the movie." It makes no mention of using the level reference beforehand.

So... if you're having trouble getting a preloader to work with levels, perhaps now you have an idea why.

EDIT - 10/28/03 - Thanks to Muzak, I need to point out that you can get the % loaded from a level, but only in certain versions of the Flash Player. On Windows, when viewing the .swf through a browser that doesn't use the Active-X control (like Mozilla), the % loaded comes through just fine. However, viewing the .swf in the Flash Authoring Environment, or in the Stand-alone Flash player, or with Internet Explorer, the getBytesLoaded function will not give the % loaded.

Flash MX method chaining

| No Comments

Just a quick little OOP tidbit for you folks out there...

"Method chaining" is the act of calling one method right after another in the same "statement" (same line of code). This is done for convenience really, as it makes manipulating an object possible in one line instead of many.

For instance, in my example posted (link below), you can create a "Photo" object and maniuplate it like this:

sunrise = new Photo();
sunrise.setLocation("sunrise.jpg").setCaption("A sunrise").setPhotoDate("8/9/03");

To enable method chaining in your custom classes, check out this code sample. Note that "return this;" is at the end of every "setter" method. This is the key to enabling method chaining, and the entire point of this entry.

.Fla pronunciation

| No Comments

How do you pronounce ".fla"? I think I'm going against the grain here, but it has always bothered me when people pronounced the Flash document file extension in a way that rhymes with "blah." To me, it even sounds blah. Why would you refer to something that you've devoted time and effort to as "blah"?

Personally, I like to pronounce it like the steak -- "fillet." I take pride in what I accomplish and think that the quality of my work is definitely above "blah" quality. When someone asks me for a .fla file at work I'll say "Sure, here's my contact manager fillet file".. like serving them up a good delicious portion of fine dining.

Comments? If I had DRK4 I'd offer up a quick poll to determine which pronunciation everyone likes best... If someone has DRK4 and wants to make another pollster app, let me know and I'll host it.

SWFHeaderInfo 1.2

| No Comments

I've updated my SWFHeaderInfo class. The changes almost all relate to better error handling for invalid files. I recommend you use this new version as it won't leave any files locked that aren't proper .swf files.

Thanks to "StartT" for pointing out the flaws. I've always used this class with valid .swf files and never ran into problems... if my former Lehigh Professors knew that I published something without extensive error handling they'd fail me for sure. ;-)

You can download the new file here (and under the download heading on the front page of my weblog). As always, report any bugs to me and I'll do my best to fix them as soon as I can.

MVC on the brain

| 2 Comments

Recently I received a coupon invitation in the mail for Kohls, a department store in the area. The invitation talk about how I was an MVC and because of that I was eligible for special sale prices. Immediately I started thinking "how am I the Model-View-Controller design pattern?" but then it dawned on me that what they were getting at was that I am a "Most Valued Customer."

Have I been programming too much lately? No, I don't think so.. but I've been absorbed in a project at work using the MVC architecture, and I just happened to be thinking about it at the time.

Typically when implementing MVC with CFMX the model is created as a CFC. This gives us the wonderful benefit of being able to use the same model for both HTML pages AND Flash RIA's. This is especially handy because I can develop an HTML interface to test out the model, and when I'm pleased everything is working correctly I can switch right over to Flash and develop a killer UI without having to worry about any of the data access - it's already been taken care of.

An additional benefit is using the "roles" attribute of cffunction. As log as the browser playing the .swf file is authenticated, the Flash app has the same authorized credentials. This protects the .cfc from being called directly from the outside world (via get/post), and gives me added security that I almost don't even need to think about. Because "access=remote" needs to be specified to use a .cfc with Flash Remoting, you open up a security vulnerability depending on what the cfc does. The .cfc acts like a webservice and can be invoked directly in the URL string. However, by using roles, we can guarantee that only authorized people can access the methods. Sweet!

Perhaps in the future I'll try and write up a tutorial of using MVC with CFMX, HTML, and Flash, but for now it's just another bullet of my giant list of things I want to accomplish in my spare time. If I get enough interest (i.e. comments) perhaps I'll escalate the tutorial to a higher priority. You decide!

Flex.org - The Directory for Flex

Archives