Tag Archives: Flash Player

AS3 Quickie – Frame Label Events

With Flash Player 11.3 and above, the ability to listen for a frame label event is now included in the runtimes. For example; if you have a MovieClip symbol with a certain set of animation within it, and you have a number of frame labels defined upon the symbol’s timeline… you can now listen for these particular frames through their individual label events and then respond to them in some way.


Requires Flash Player 11.3 or above!

To get this working only takes a few steps in your ActionScript code. For each frame label you wish to respond to, you must create a new flash.display.FrameLabel object and add an event listener to it. In order to utilize Event.FRAME_LABEL you must target Flash Player 11.3 or above.

You’ll (of course) need to define some frame labels across the timeline. Here, we’ve established 4 frame labels within a MovieClip symbol:

In ActionScript, we must perform the necessary imports:

import flash.events.Event;
import flash.display.FrameLabel;

We then need to assign an event listener to each frame label we wish to respond to. In order to accomplish this, we read all of the symbol frame labels into an array in order to dynamically create flash.display.FrameLabel objects which have event listeners attached to them, listening specifically for Event.FRAME_LABEL:

labelsArray = angyFace.currentLabels;
for(var i:uint=0; i<labelsArray.length; i++){
	var frameLabel:FrameLabel = labelsArray[i];
	frameLabel.addEventListener(Event.FRAME_LABEL, onFrameLabel);
}

And follow through with a method to handle the event, itself:

private function onFrameLabel(e:Event):void {
	//do something
}

Of course, depending upon our requirements, we may want to register each frame label object specifically in order to manage it appropriately. For simplicity – this example project has no cleanup routine associated with it.

The full code is below. Note that the FLA contains upon the Stage a TextField with the instance ID of statusField and a MovieClip symbol instace called angryFace which contains the 4 frame labels we are registering:

package  {
	import flash.display.MovieClip;
	import flash.display.FrameLabel;
	import flash.text.TextField;
	import flash.events.Event;
	
	public class Main extends MovieClip {
		public var statusField:TextField;
		public var angyFace:MovieClip;
		
		private var labelsArray:Array;
		
		public function Main() {
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			labelsArray = angyFace.currentLabels;
			for(var i:uint=0; i<labelsArray.length; i++){
				var frameLabel:FrameLabel = labelsArray[i];
				frameLabel.addEventListener(Event.FRAME_LABEL, onFrameLabel);
			}
		}
		
		private function onFrameLabel(e:Event):void {
			statusField.appendText("\n" + e.target.frame + ": " + e.target.name);
		}
		
	}
	
}

Want the full package? Download below:
Packaged code and Flash Professional CS6 project

Using Advanced Telemetry with Monocle

Project Monocle (codename) is an upcoming tool from Adobe to profile ActionScript 3 (Flash Player and AIR) applications on both desktop and mobile. It provides an amazing level of insight into just about all aspecs of an application across time. If you would like a general overview of its capabilities, here is a nice video.

Monocle has been in private beta for some time now, and was recently made available much more widely through a public beta program:


Note that even though the beta is now public, I believe many things are still restricted to the NDA agreement of the prerelease program, so I will not be getting into any specifics in this article about Monocle usage itself. Basically, so long as Monocle is running on your system, any SWF with advanced telemetry enabled will be able to be profiled within the application when it is run from a website, development environment, mobile device, or whatever.

Using Flash Builder 4.7

The easiest way to get going with Monocle is to use the beta 2 of Flash Builder 4.7 to enable telemetry and compile your projects. The process is super easy as there is a little checkbok (Enable detailed telemetry) in the ActionScript Compiler section of the project properties dialog which allows you to easily turn this feature on and off.

There are a few things to note in regard to this, however. This option is only available on pure ActionScript projects since at this time, only pure AS3 projects can be compiled using ASC2.0 – which is the compiler FB4.7 uses to compile AS3 projects and insert the telemetry features into the compiled app. As a result, you cannot use this with Flex projects with Flash Builder (yet, anyway).

Once telemetry has been enabled for a project, the next step would be to run the Monocle application so that it is listening for telemetry data. Starting a capable SWF (using Flash Player 11.4 or AIR 3.4 and above) will trigger a new Monocle profiling session.

In the above example, I’m using a simple Hallowe’en themed Away3D AS3 project in FB4.7 with advanced telemetry enabled in order to test out Monocle. Since Monocle has some rather special Stage3D profiling features, this will enable me to profile the full range of available options provided by the application.

Switching over to Monocle, we can see that all of the data for this session has been collected in gorgeous detail. One of the things that is really impressive with the project is that all of this data is interactive – even the Stage3D bits!

Using Flash Professional

If using older Flash Player and AIR projects in Monocle, we have an alternative to re-compiling everything through FB4.7 – we can even use this method along with Flash Professional CS6! This method takes a previously compiled SWF and runs it against a small Python script to shuffle the bits around and enable telemetry.

NOTE THAT THIS METHOD IS NOT A FINAL SOLUTION BUT SIMPLY WHAT WE MUST USE AT THIS PRESENT TIME IF NOT COMPILING WITH FB4.7

The first thing we need to do is get Python installed on the system we’ll be working with. I’m using a Windows 7 machine so downloaded the .msi installer which provided an option to add Python to my PATH options. Very convenient.

After installation, we can then open up a command prompt and run the script (add-advanced-telemetry.py) that comes bundled with the Monocle package, feeding in the SWF we wish to enable telemetry on as an argument. Again, this isn’t the best way to enable telemetry… but with some trial and error – it is workable.

New Flash Runtimes Goodies on Labs

Adobe rolled out a bunch of new Flash goodies on the Labs site this evening; a new version of SWF Investigator, a Configurator release candidate, and the first betas of Flash Player 11.5 and AIR 3.5! We also have a new updater for Flash Professional CS6 and the announcement of the Adobe Game Jams… phew!


SWF Investigator
It’s amazing how much is packed into this little AIR application! Have a look through one of your own SWF files and check out the about option to see some of the integrated libraries involved. Complex stuff!

Adobe SWF Investigator is the only comprehensive, cross-platform, GUI-based set of tools, which enables quality engineers, developers and security researchers to quickly analyze SWF files to improve the quality and security of their applications. With SWF Investigator, you can perform both static and dynamic analysis of SWF applications with just one toolset. SWF Investigator lets you quickly inspect every aspect of a SWF file from viewing the individual bits all the way through to dynamically interacting with a running SWF.

Admittedly though… the app could use a bit of love from a designer :)


Flash Professional CS6 Updater
This was actually released earlier today: an updater for Flash Professional CS6 which includes the following new features:

  • Support for AIR 3.4 and Flash Player 11.4
  • Direct Deployment to iOS Devices
  • Native iOS Simulator Support 
  • High Resolution Retina Display Support
  • Toolkit for CreateJS 1.1

Here is a video overview:


AIR 3.5 beta

Adobe AIR allows developers to package their Flash-enabled content into apps that reach over 1 billion personal computers and 500 million mobile devices.

The primary goals of this release are bug fixing, adding Jellybean support, and iOS app enhancements. These features are not insignificant:

  • Debug stack trace in release builds of Flash Player — This feature enables developers to display stack trace info in release and debug builds.
  • Packaging Multiple Binaries — This feature enables developers to include third party static libraries and frameworks and package these with ANE.
  • Shared ByteArray support for ActionScript Workers — This feature enables developers to share memory between multiple workers.
  • Packaging and loading multiple SWFs on iOS — This feature will allow developers to load multiple swfs, that contain ActionScript bytecode on iOS .

Flash Player 11.5 beta

Flash Player is a cross-platform, browser-based application runtime that provides uncompromised viewing of expressive applications, content, and videos across browsers and operating systems.

The primary goal of this release is bug fixing… but there are a few neat features to note:

  • Shared ByteArray support for ActionScript Workers — This feature enables developers to share memory between multiple workers.
  • Debug stack trace in release builds of Flash Player — This feature enables developers to display stack trace info in release and debug builds.

With the Flash Player betas, we can now subscribe to automatic updates similar to the release version of the Flash Player. Also of note is a new Twitter account, @FlashPlayerBeta, for getting notice of important runtimes updates.

 


A lot of activity… and I expect to see more very soon once Adobe releases project “Monocle”.

Flash is dead“, right? LOL!

Flash Runtimes and Tooling Announcements

Adobe today released both Flash Player 11.4 for desktop browsers and AIR 3.4 for both desktop and mobile operating systems. This release includes new features as well as enhancements and bug fixes related to security, stability, performance, and device compatibility for the runtimes previously code-named “Dolores” as outlined in the Adobe roadmap for the Flash runtimes.


Flash Player 11.4

  • Concurrency (ActionScript Workers)
  • Stage3D “constrained” profile for increased GPU reach
  • StageVideo.attachCamera
  • Camera.copyToByteArray/Camera.copyToVector
  • LZMA support for ByteArray
  • Sandbox Bridge support
  • Compressed texture with alpha support for Stage3D
  • Licensing support: Flash Player Premium Features for Gaming


Adobe AIR 3.4

  • Stage3D “constrained” profile for increased GPU reach
  • LZMA support for ByteArray
  • StageVideo.attachCamera
  • Camera.copyToByteArray/Camera.copyToVector
  • Compressed texture with alpha support for Stage3D
  • iOS 5.1 SDK Support
  • Exception Support in Native Extensions for iOS
  • iOS Push Notifications
  • AIR direct deployment (without iTunes)
  • Deprecated Carbon APIs for AIR
  • Ambient AudioPlaybackMode
  • Exception Support in Native Extensions for iOS

Not only did Adobe announce runtimes releases today, but also some updates around tooling. Flash Professional CS6 will be getting a major update in September and the Flash Builder 4.7 beta will open up to the public next week! I’ve listed some of the updates and features below.


Flash Professional CS6 updater

  • ToolKit for CreateJS 1.1
  • Support for Flash Player 11.4
  • Support for AIR 3.4
  • iOS simulator support
  • Direct on-device deployment


Flash Builder 4.7

  • Support for Apache Flex 4.8
  • Support for Flash Player 11.4
  • Support for AIR 3.4
  • USB debugging improvements
  • iOS simulator support
  • Direct on-device deployment
  • and more… (Falcon compiler, anyone?)

AS3 Quickie – MouseEvent.RELEASE_OUTSIDE

With Flash Player 11.3 and above, the ability to detect a mouse release outside of embedded Flash content makes a triumphant return! Missing in ActionScript 3.0 from Flash Player 9 onward, crafty developers have come up with some strange hacks to compensate for the missing event – but with the modern Flash Player runtime such trickery is no longer needed :)


Requires Flash Player 11.3 or above!

To get this working only takes a few steps in your ActionScript code. Everything relies upon classes that already exist – such as flash.events.MouseEvent, but you must target Flash Player 11.3 or above.

Perform the necessary imports:

import flash.events.MouseEvent;

We then simply need to assign an event listener to our Stage, listening for the new RELEASE_OUTSIDE event:

stage.addEventListener(MouseEvent.RELEASE_OUTSIDE, onMouseReleaseOutside);

And follow through with a method to handle the event, itself:

private function onMouseReleaseOutside(e:MouseEvent):void {
	//do something amazing
}

To see this working, click anywhere upon the Stage and drag the mouse cursor off past the edge of the Stage and the release. In the embedded example above, you will see the status message update to reflect this.

The full code is below. Note that the FLA contains upon the Stage a TextField with the instance ID of statusField:

package  {
	
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class ReleaseMouseOutside extends MovieClip {
		
		public var statusField:TextField;
		
		public function ReleaseMouseOutside() {
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			stage.addEventListener(MouseEvent.RELEASE_OUTSIDE, onMouseReleaseOutside);
		}
		
		private function onMouseReleaseOutside(e:MouseEvent):void {
			statusField.appendText("\nMouse Released! (outside)");
		}
		
	}
	
}

Want the full package? Download below:
Packaged code and Flash Professional CS6 project

Need to update Flash Professional to support a newer version of the runtime? Chris Griffith has a great step-by-step rundown on how to do it.