Tag Archives: ActionScript

Tech Tips: Compress Transparent PNGs with Flash

Do you use transparent PNGs in Flash, Flex or AIR? Want to cut your application file size in half?

Problem:
Embedding transparent PNGs dramatically increases the size of your Flash, Flex and AIR applications. Photoshop and Fireworks dot not have any compression available for transparent PNGs (that I am aware of).

Solution:
Import your PNGs into Flash, give them a linkage id, and export the file as a SWF. Make sure to set your compression level in the publish settings (default is 80%). Using this method, I was able to cut the file size in half for a number of applications.
Read more

Filed under Technology

Flashbelt Day 1: Quite the Canvas

I’ve just finished up day one of the Flashbelt conference here in Minneapolis. Flashbelt is one of the premier conferences in the country oriented around Adobe’s Flash player. The conference is aimed at animators, designers, developers, project managers, ad agencies and so on; pretty much anyone who is involved with creating content for the ubiquitous Flash player.

Flashbelt attracts a lot of well known speakers, many of the “heavy hitters” in the Flash scene – guys like Seb Lee-Delisle, Dr. Woohoo, Minneapolis’ own Danny Patterson, and so on. These names probably don’t mean much to the uninitiated, but if you’re into the geekiness like us, these people can almost be rock stars. I’m one of the Flash developers at the Nerdery, so myself and a few others from the Nerdery are at the conference checking things out.

The day started with a keynote by Richard Galvin and Paul Burnett from Adobe. These guys have intimate knowledge about Flash; they mange the Flash product lines. They talked about where the Flash platform is at currently and where it’s going.

Perhaps the most interesting point was how Adobe really wants to move the current Flash player to more devices than just computers, like TVs and mobile phones (Flash for iPhone anyone? We Flash devs can dream). Getting Flash onto these devices is the logical next step, and would be a boon for getting interactive content to more people.

The rest of my day was spent in sessions dealing with the more nerdy development side of the Flash world. I’ve gotta make sure to give mad props to our own Chris Black and Minh Vu, who gave a presentation about their experiences developing Skimmer, Fallon’s “lifestreaming” application. Chris and Minh did a great job presenting, and demonstrated that they really know their stuff.

The day ended with a session by Joel Gethin Lewis, who I’m not even sure does Flash development. Instead, Joel works for a firm in the UK that puts together real-world “interactive experiences,” things like using laser pointers to “paint” projected artwork onto buildings or making interactive stage lighting for the band Massive Attack.

It may seem odd to have a session that isn’t directly connected to the Flash platform, but apparently this is what they always do at Flashbelt. It shows that Flashbelt is about more than just coding or content production. It’s about being inspired and seeing what’s possible.

And I think if I had to sum up this first day of Flashbelt, it would be just that: be inspired. There was plenty of technical mumbo-jumbo to go around at Flashbelt, but the fact is that Flash transcends its technical backing (which has come a long way, I might add). For many years now, Flash has been arguably the most ubiquitous platform for serving up interactive experiences.

Think of this: Flash is the technology enabling YouTube and all other video sharing websites, which is changing the way we consume long entrenched forms of mass-media. Or imagine you’re an artist with an interest in the interactive-type things. You can make something for Flash, and suddenly your art can potentially be seen by millions of people who have the container waiting to show your art. The install base for Flash player is in billions of machines – that’s quite a canvas!

So it’s a good thing for all developers to remember as we come up with solutions for our clients: be inspired, think big, think of unique things, think of what people are going to want to use. Flash is one of the technologies we can use to bring the content and experiences that people are looking for.

Oh, and the worst part of Flashbelt so far? Having to endure the hokey smooth jazz that is always playing over the restroom speakers.

Tech Tips: Prevent scaling in ActionScript projects

Problem:
The scale mode for ActionScript projects is set to allow zooming by default even when the width and height are set to fixed sizes. This can distort your website when the user uses ctrl-mouse scroll wheel or hits ctrl-plus / ctrl-minus.

Solution:
Set the stage scaleMode to “noScale” and configure the containing div to stretch at 100% for the height and width. You may also want to set the stage alignment to “T” which will align your content to the top of the page. This will work in AS2 as well but the ‘S’ is capitalized in Stage.
Read more

Filed under Technology

Remix tunes with online music mixer

In the immortal words of our own Tom O’Neill check out the latest badass ActionScript/PHP project to come out of The Nerdery:

You can get to remixing your own tunes on Remix Galaxy.

Tech Tips: Embedded Fonts & Filters with Input Text in ActionScript

Problem:
We need a TextField of type TextFieldType.INPUT that has embedFonts set to true and has an inner drop shadow filter. Sounds easy enough right? The first problem is that DropShadowFilter’s don’t work correctly with TextFields created using ActionScript. The second problem is that setting embedFonts to TRUE and leaving default text empty on a TextField with type TextFieldType.INPUT causes the field not to be selectable.

Solution:
Lets tackle the DropShadowFilter first. After many failed attempts at getting filters to render correctly on TextFields the next best solution was to create a sprite that sites right behind the text field that renders the filter.
Read more

Filed under Technology

Tech Tuesday: Validate Twitter credentials in AIR

Problem: Your AIR application needs to validate the username / password and handle failure gracefully within the application. If the user enters the wrong information you do not want them to be prompted with a Windows prompt asking them to enter their Twitter username / password. If the application needs to hold on to the credentials for any reason the Windows authentication to the API will break the AIR application.

"The server twitter.com at Twitter API requires a username and password."



Solution:
The URLRequest object has a property called 'authenticate' that must be set to false.

Actionscript:
  1. /**
  2. *
  3. * Setting result.authenticate to false prevents the operating system from
  4. * taking over and prompting the user to authenticate.  It allows the AIR
  5. * application to take the correct action.
  6. *
  7. */ 
  8. private function twitterRequest (url : String):URLRequest
  9. {
  10.    var result:URLRequest = new URLRequest (url);
  11.    if (this.authorizationHeader){
  12.       result.authenticate = false// <--------- Most Important Line of Code!!!!
  13.       result.requestHeaders = [this.authorizationHeader];
  14.     }
  15.     return result;
  16. }

Most of the code from the example attached is from the Google code repository.

Here are the source files to an example AIR application that uses actionscript to verify Twitter credentials without prompting a windows box on failure.

I would like to give credit to Clayton (file_cabinet) for coming up with the solution to this problem. Thanks Clayton!

This was originally posted on blackcj.com, Chris Black's personal blog. Chris is a Senior Developer at Sierra Bravo.

Filed under Technology

Tech Tuesday: Using anchor tags in ActionScript TextFields

This example is for anyone who needs to use anchor tags in ActionScript TextFields. If you're using AIR then the best route is to use an HTMLLoader to load in the raw HTML. If an HTMLLoader is not an option you can use this example to create a wrapper class that mimics the anchor tag functionality. Before we get started it is important to note that TextFields have a number of properties, formats, and styles available which all have an effect on the way text is rendered. This example takes advantage of a specific set of properties in order to accurately determine the line number and char location of certain strings. Variables may require some adjustments / tweaks (or may not work at all) if the TextField properties are changed.
Read more

Filed under Technology