Archive for the ‘ActionScript’ Category

I’m posting this for those folks that don’t attend your local Flex or Flash Platform User Group.

Yesterday there was a great presentation for the user groups by David George titled Tips and Tricks for Delivering More Responsive Flex Applications.

David is a developer on the Flex team at Adobe, and was able to share a bunch of pointers on how to improve the performance of your Flex applications. The great thing about this presentation is that he not only shares the tip or trick on how to do something, but also why it’s a good idea. He explains a little into the mechanics of how the Flash Player interprets your code at a few points so that you can see why this tip could help your application.

If you’re getting into Flex development, it’s worth checking out. It’s about one hour long.

http://adobedev.adobe.acrobat.com/p71169528/

Debugging can sometimes be fun, or a nightmare. This usually depends on the project, your current mood, and the types of bugs you’re trying to resolve.

Often, fixing a bug means that you read through your code, follow the logic involved, spot the error and fix it. Other times, a bug may only be killed by means of voodoo rituals, and the throwing of a virgin into a volcano. At least it seems that way at times.

A few new articles appeared in the Adobe Developer Center this afternoon, and one of them was a good primer on debugging in Flash by David Stiller. It covers the basics such as using trace () statements, and looping through your objects, then moves on to using the Debugger Panel and debugging your swfs in a browser.

There’s some good info here; for those just starting in development, or who don’t do much development, you might learn something new - for those more experienced, it can a nice little refresher on some basics.

One of the nicest features of the article is that it explains how to actually use the Debugger Panel. Using this thing is a bit of black art to some, as the documentation hasn’t always been as clear as it could be. Many of the Flash developers I know that use it have learned to use it by means of repeated trial and error. The article also mentions some of the third-party debugging tools such as X-Ray.

So, if you’re new to debugging, or just want to read up a little, check it out:

http://www.adobe.com/devnet/flash/articles/debugging_actionscript.html

This is a great reference from Tink on Macintosh File Types (macTypes), listing what the type codes are for different file types. I’m linking this as it’ll make it easier for me to find in the future, as well as to add one more thing.

These file types can be used with FileReference.browse () and FileReferenceList.browse () to filter the types of files your users can be allowed to select when browsing for files to upload. On Windows, you specify the file extension to filter by. In OSX, you can use the macType.

This works great - provided that the file was created on a Mac, by an application that sets the macType when the file is created. But this isn’t always the case.
Read the rest of this entry »

If you’re using Xcode for your ActionScript work, you really should be checking out the Xcode section of OSFlash. There’s some pretty cool stuff showing up there. It’s where I found XASH, and Sam Robbins’ Actionscript code highlighter plugin can be found there as well.

If you’re using that plugin, it adds some language definition files to Xcode for AS code completion. Michael Bianco has created a new set of definition files that you can copy into Xcode that updates the code completion for Flash 8, as well as adding code completion. As much as I like Xcode for writing AS, I really missed the code completion that you get with the Flash IDE or with SEPY. It’s nice getting the completion of the function names, but what I really missed was the parameter suggestions. Seems like no matter how many times I use setInterval(), I always manage to forget what order the parameters are entered in.

Pretty awesome, huh? Now if we can get the Class Modeller to work…

Links:


Xash - Xcode ActionScript Help is new project recently added to osflash.org.

Xash allows you to browse Flash’s help files outside of the help panel. It’s got it’s pros and cons, but I really like it so far. First, it’s a lot faster than the built-in help panel. Second, it allows you to view the help files without having to open Flash, so if you’re working on an AS only project using mtasc, you’ll have quick access to the docs.

On the downside, there’s no searching yet, and you can’t filter the book listing like Flash does, but those features are planned, and since it’s open-source, you could add that if you get impatient. Also, as a downside to Windows users, it’s currently for Macs only.

Either way, this is a great app that Mac Flash developers should check out.

Update: - These instructions don’t work 100% with the files from Flex 2 Beta 2, or the recently released Flex SDK. I’ve posted some new instructions here: http://www.joshbuhler.com/2006/04/17/using-the-flex-sdk-with-xcode/

Yesterday I mentioned a site that had instructions on how to compile ActionScript 3.0 files on your Mac using the command line compiler.

That’s all well and good, but once you get going on a project, it can get a little tiring typing out the commands to compile your swf each time. However, if you’ve been using Xcode for your ActionScript work, you can set it up to compile your AS3.
Read the rest of this entry »

Update: - You no longer need to download the Windows build to pull out the files needed to to this. You can now dowload the Flex SDK from labs.macromedia.com. Once you do that, you can also setup Xcode to work with the Flex SDK. I’ve posted the new instructions here:

http://www.joshbuhler.com/2006/04/17/using-the-flex-sdk-with-xcode/


So… you want to start playing with Flex Builder 2 Alpha, and Player 8.5, but you’re on a Mac. And there weren’t any links to downloads for your Mac on labs.macromedia.com. What’s a Mac-using Flash-developer to do? A Mac version of the 8.5 player is available in the download, but what about Flex Builder and the compiler?

I wondered the same thing, and while at MAX the last few days, tried to find the answer to this question. Basically, Flex Builder 2 for Mac is a ways off, but because the compiler is Java-based, you can still use it on your Mac. I spoke with Mike Chambers for a few seconds about this, and he told me that there would be instructions soon on how to compile your AS3 stuff on Mac. But… I couldn’t wait, and tried figuring it out myself. As I was really tired after arriving home last night, that effort lasted for only a few minutes. But after searching today, I found some instructions online.

Right now, the site doesn’t appear to be working, however you can view it by using a Coral Cache of the page:

http://www.mook.co.uk.nyud.net:8090/~alisdair.mills/mxmlc_compiler_osx.html

I downloaded the Alpha, pulled out the bits I needed, and was on my way. Hopefully, this info will be added to the Wiki over on the labs page for other Mac users, but until then, this should at least get you started.

Also, forgive me if this is “old news”, but I really haven’t been online for the last week or so. I used the PC’s at MAX to check email, and that was about it. I’m just now weeding through the 200-300 or so new articles I have in NewsFire, and trying to get caught up on things. I’ve got some good stories to tell, and my impressions of my first MAX to share over the next few days.

Update: If you’re one of those Mac folks who also like to use Xcode for your Flash work, you can also setup Xcode to use the mxmlc compiler.


Here’s one more new Flash 8 feature worth mentioning.

UPDATE: My bad - I didn’t realize that this was already in Flash MX 2004 - I guess I just never saw it in there, so I assumed it was new.

Ever have a swf that doesn’t work because you happened to use something in your code that isn’t supported in the version of Flash you’re targeting? A while ago I was helping one of our designers here fix some code where he was trying to use the MovieClipLoader class, and it just wouldn’t work. After spending about 15-20 minutes of me checking and rechecking his code, trying to determine where the issue was, he asked me if it mattered what version of Flash he was building for. Turns out he was targeting Player 6, so of course, it wouldn’t work.

Flash 8 now adds highlighting of incompatiple ActionScript in the Actions Panel, based on the Player version specified in your Publish Settings. It won’t highlight the actual ActionScript in the text-editor pane, but in the pane to the left of the text editor, the incompatible methods and classes will be highlighted. In this screenshot, my Publish Settings are set to build for Player 6.

Of course, the info on what versions of the Player support a particular method or class are listed in the Help Docs with each method/class/property etc. but this makes for a nice quick reference.

About a month ago I posted an example swf of the new file uploading features of Flash 8. I've had a few requests for the source files, so here they are.

Links:

One note: depending on where you put these files, you may need to adjust the url's used by the swf. You'll find them in main.as beginning on line 13.

  1. // url vars
  2. var imageFolder:String = "images/";
  3. var uploadScript:String = "fileUpload.php";

Just a quick mini-tutorial on using the ternary operator in ActionScript. One of those things that shows up in my search logs, so the next time someone searches for it, they should be able to find it.

The ActionScript Ternary Operator

The ternary operator, "? :", is basically a shorcut for writing quick conditional statements that evaluate to either true or false. Similar to an if/else statement, you use them to make a decision in your code, and act based on that decision.

Here's the syntax:

  1. // using the ternary operator
  2. (condition) ? isTrueAction : isFalseAction;
  3.  

The ( ) around condition are optional, however they do help to clearly illustrate the condition. The code above is the same as writing:

  1. // the same thing, only more typing
  2. if (condition) {
  3.         isTrueAction;
  4. } else {
  5.         isFalseAction;
  6. }
  7.  

Now, you won't be able to use this for something that has multiple statements after the condition like you can in an if statement, but it does have it's uses for quick little things. For example, you couldn't use it for something like this:

  1. // this can't be written out using ternary operators
  2. if (condition) {
  3.         isTrueAction;
  4.         var bob:String = "something";
  5.         goDoSomethingNow();
  6. } else {
  7.         isFalseAction;
  8. }
  9.  

But it's great for something like this:

  1. // this is a great use for ternary operators
  2. (superBowlWon == true) ? gotoDisneyland() : goHome();
  3.  

Or even for checking if a number is even or not.

You can also use this technique to set values for variables:

  1. // setting a variable like this...
  2. var pillToTake:String = (stayInMatrix == true) ? "blue" : "red";
  3. //
  4. // is the same as doing this:
  5. if (stayInMatrix == true) {
  6.         var pillToTake:String = "blue";
  7. } else {
  8.         var pillToTake:String = "red";
  9. }
  10.  

So, as you can see, using this operator can save you time by requiring less typing in a few situations. Now, it's not the solution to everything, but as you start using it more, you'll start to wonder how you worked without it. (Maybe not, but it'll make me feel better if I can imagine that I've somehow improved your life.)

Also, after I finished writing this, I decided I wanted to try and determine which method is faster, to see if there's another argument for learning how to use this stuff. So in a pretty informal, and un-scientific way, I ran the following test:

  1. // testing ternary operator vs. if/else
  2. // just copy and paste onto the main timeline, and run
  3. //
  4. var loops:Number = 10000;
  5. //
  6. // ternary test
  7. var startTime1:Number = getTimer();
  8. for (var i:Number = 0; i < loops; i++) {
  9.         var testNum:Number = Math.floor(Math.random() * 100);
  10.         var isEven:Boolean = ((testNum % 2) == 0) ? true : false;
  11. }
  12. var endTime1:Number = getTimer();
  13. var totalTime1:Number = endTime1 - startTime1;
  14. //
  15. // if/else test
  16. var startTime2:Number = getTimer();
  17. for (var i:Number = 0; i < loops; i++) {
  18.         var testNum:Number = Math.floor(Math.random() * 100);
  19.         if ((testNum % 2) == 0) {
  20.                 var isEven:Boolean = true;
  21.         } else {
  22.                 var isEven:Boolean = false;
  23.         }
  24. }
  25. var endTime2:Number = getTimer();
  26. var totalTime2:Number = endTime2 - startTime2;
  27. //
  28. trace("Total Times: \n");
  29. trace("\tTernary: " + totalTime1);
  30. trace("\tif/else: " + totalTime2);
  31.  

Running this test on my PowerMac with dual G5 2.0, and 1 GB ram, I came up with the following averages after running it 20-30 times: Ternary: 201 ms, if/else: 195 ms. Now, your results may vary, and this most likely isn't the best way to test something like this, but it's enough for me to see that there is a speed difference, but it's not enough of a difference to really make me stick to if/else exclusively.

Entries (RSS) Comments (RSS)