You are here: Recent News » flashcoders » undocumented » Flash 8

 

Flash 8

There are several new features accessible from Flash 8 Beta Player. This page is trying to list all of these new features, including improvements in performance. MTASC 1.09 enables you to start experimenting with theses new features right now! (don’t forget to add -version 8 to the commandline). Get Update of Std directory for latest features.

If you are using Flashout to visualize swfs inside of the Eclipse IDE, you might want to check if have flash player 8 registered for Internet Explorer ( not Firefox ).

You can also use Convert2SWF8 for Windows or swfTo8ConvX for MacOS X to drag-and-drop compiled SWFs. You can also use the translated Export to SWF8 Instructions.

swfmill allows you to generate Flash 8 SWFs directly from XML by adding version=”8” to the movie tag.

“There is a new feature called ‘Show redraw regions’ in the Flash Player which will allow you to see which areas of your movie are refreshed every frame” Tinic Uro.

Note: The experiments described on this page may or may not describe practical usage of the actual Macromedia Flash 8 technology when it ships. In previous Player compatibility testing people have discovered keywords which were reserved within the Player, but whose functionality had not been fully implemented (whether due to problems found during early testing, scheduling demands, alternative paths to similar goals, etc). It’s certainly fun to play with these commands now, but please don’t commit to using them in real projects until the functionality is confirmed within the Macromedia documentation for this release.

The latest versions of the Flash 8 player are:

WIN 8,0,22,0
MAC 8,0,15,0

Filters

Flash 8 Filters allow you to add special effects to your MovieClip, such as drop shadows or blur. The list of filters is available into mtasc/std/flash/filters directory. You can assign one or several filters to a MovieClip using the new .filters Array property :

  var myfilter = new flash.filters.DropShadowFilter();
  // customize the filter through public properties
  mc.filters = [myfilter];

An example of Some Filters.

(Filters are also usable on Buttons and TextFields).

Adding a filter to a movie clip automatically turns Bitmap Caching on for that movie clip. Removing the filter (mc.filters = undefined) will turn off Bitmap caching, except if you mc.cacheAsBitmap = true before disabling the filters.

WARNING: filters can cause hard to debug conditions. Objects with filters enabled inside an object with filters enabled crash the IE ActiveX flash player (8.0.15). Under FireFox, the player can crash but will mostly produce visible artifacts. To check if the crash is caused by FP8 features, test your file under Flash Player 7.

Flash crash under IE6 Flash artifacts under FireFox Video of the artifacts

Blending Modes

Flash 8 Belnding Modes are another way to obtain special effects by changing the way the color of each point of the MovieClip is blended with the background. The list of blending modes is available through the new class MovieClip.BlendModeType (see mtasc/std/MovieClip/ directory). You can change the blending mode of a clip by editing the new .blendMode String property :

  mc.blendMode = "lighten";

An example of Blending Modes Blend modes with Video

Geometry Classes

Matrix, Point, Rectangle and ColorTransforms are new classes from the flash.geom package (see mtasc/std/flash/geom directory for their methods).

“flash.geom.* is implemented in player actionscript, not ASNative” says Patrick Mineault. This can be a serious bottleneck =(. (Nicolas : this means that it’s not accelerated, so don’t expect any speedup, but’s it’s nice to share same datastructures so it will work as a standard definition).

TextField Extensions

Instances of the TextField class have several new public fields:

  • .filters : like MovieClips
  • .antiAliasType : can be assigned to a value of among the ones defined in flash.text.TextRender.AntiAliasType
  • .gridFitType : can be assigned to a value among the ones defined in flash.text.TextRender.GridFitStyle
  • .sharpness : Number
  • .thickness : Number

MovieClip Extensions

Instances of the MovieClip class have several new public fields:

  • .opaqueBackground : Number

will make the background within the bounding box of actual movieclip content be of the color assigned to the property. setting it to false will remove the background.

There are some more properties in MovieClip.prototype whose function is still undocumented. You can find these in the “Mysteries” section below.

Bitmap Display

A new class : flash.display.BitmapData, provides pixel-level acess to bitmaps.

var img_bmp = new flash.display.BitmapData(256,256,true);
for ( var y:Number=0; y<256; y++ ) {
        for ( var x:Number=0; x<256; x++ ) {
                var a:Number = y;
                var r:Number = x;
                var g:Number = 256-x;
                var b:Number = 256-y;
                var c:Number = (a<<24)|(r<<16)|(g<<8)|(b<<0);
                img_bmp.setPixel32(x,y,c);
        }
}
 
_root.createEmptyMovieClip("bmp", 1);
_root.bmp.attachBitmap(img_bmp, 2);

Confirmed: You can place a MovieClip into a BitmapData by using BitmapData.draw(some_mc);

The second parameter of BitmapData.draw() allows you to specify a transformation matrix for the movieclip. So for example if you rotate the movieclip and then draw it into a BitmapData object without passing a transformation matrix, it wont be displayed in the bitmap rotated.

However you can use:

a=new BitmapData(mc._width,mc._height,true) a.draw(mc,mc.transform.matrix)

To draw it as it is seen. You can also use the transformation matrix parameter to move the position of the movieclip in the bitmap.

setPixel example setPixel, getPixel example

When creating a BitmapData, you can give up to 4 parameters :

  • the width, in pixels
  • the height, in pixels
  • does the bitmap contain alpha values (true or false)
  • the default fill color, as 0xAARRGGBB

When attaching a bitmap into a MovieClip, you can give up to 4 parameters :

  • the BitmapData instance you want to attach
  • the depth where you’re attaching it
  • (not verified) a String for bitmap interpolation “auto” “true” or “false”
  • (not verified) a Boolean , usage unknown

Text Renderer Control

A new class : flash.text.TextRender with only a static method.

FileReference

Two new classes : flash.net.FileReference and flash.net.FileReferenceList, complete usage unknown right now, but here is how you get a browse dialog:

    var fileRef = new flash.net.FileReference();
    btBrowse.onRelease = function  () {
        if (fileRef.browse()) {
            txtInfo.text = "File Name:" + fileRef.name;
        }
    };

Browse Example

It looks like it is the same as the Central implementation, you can find the documentation on it on the Macromedia Livedocs website.

File Download Example - Links to swf implementations of upload and/or download and provides an AS2 download implementation which you can download and deconstructed. The example avoids the use of components, and is 100% code, please feel free to suggest impovements. (To avoid compile issues in MX 2004, ‘flash.net.FileReference’ is passed when creating an instance; d=new Dnload(_root,”DnLoad.as”,30,30,new flash.net.FileReference()); and then the hex player value can be changed to 8 )

Methods of FileReference utilised:

download(file:Object):Boolean (success or failure)
onCancel(file:Object)
onOpen(file:Object)
onProgress(file:Object, bytlesLoaded:Number, bytesTotal:Number)
onSelect(file:Object)
onComplete(file:Object)

Where file object is

{name:fileName, size:fileSize}

File Upload Example - As of posting, he hasn’t gotten the event callbacks to work. So it uploads the file, but no progress bar or completed notification.

Backend scripts (CF, c#, PHP) used for upload can be found here

Methods of FileReference utilised:

browse()
onCancel(file:Object)
onSelect(file:Object)
onOpen(file:Object, err, response)
onProgress(file:Object,bytesLoaded:Number,bytesTotal:Number)
onHTTPError(file:Object,err:Number)
onIOError(file:Object)
upload(uploadControlPHP:String) returns boolean

possible simple use??

var fileRef = new flash.net.FileReference();
fileRef.addListener({onOpen:function(f){(f.upload(”http://www.mysite.com/upload.php”)?/*success*/: /*failure*/},onProgress:function(f,b,t){var percent:Number=Math.round((b/t)*100);_root.t_txt.text="file:"+f.name+" of "+f.size+" has uploaded "+percent+"%."}};
fileRef.browse();
}

Multiple files can be uploaded with ‘FileReferenceList’ ...

Bitmap Caching

public cacheAsBitmap : Boolean

If set to true, Flash Player caches an internal bitmap representation of the movie clip. This can increase performance for movie clips that contain complex vector content.

var mc:MovieClip = this.createEmptyMovieClip("container", this.getNextHighestDepth());
mc.cacheAsBitmap = true;

Note, this API can significantly increase rendering performance in the player, especially when moving large number of items at the same time. However when scaling or rotating, the bitmap is redrawn so it will not change anything compared to Flash7.

An example of Bitmap Caching Another Example

Performances

Here is a nice test suite comparing Flash 6 and Flash 7 files played back by the Flash 7 player and the Flash 8 beta player.

http://oddhammer.com/actionscriptperformance/set3/index.html

Another benchmarcking system is available here

and the result's database

It would be interesting if someone could do a PC vs MAC plugin test.

ExternalInterface API

The ExternalInterface API provides seamless Flash / JavaScript communications. Basically, you can make syncronous function calls from Flash to JavaScript and JavaScript to Flash.

Here are some examples:

JavaScript to Flash

ActionScript

import flash.external.ExternalInterface;
 
class ExternalInterfaceTest
{
    public function ExternalInterfaceTest()
    {
        //first arg name of function exposed to JavaScript
        //Second arg is function that is actually called
        ExternalInterface.addCallback("actionScriptFunction", this, actionScriptFunction);
    }
    
 
    public function actionScriptFunction(input:String):String
    {
	trace(input);
	return input;     
    }
}

HTML / JavaScript

<SCRIPT LANGUAGE="JavaScript">
    //This line gets access to the Flash player in the html page.
    //flashId, is the id use for the flash instance in the page
    var flash = (navigator.appName.indexOf ("Microsoft") !=-1)?window["flashId"]:document["flashId"];
    flash.actionScriptFunction("Hello World.");
 </script>

Flash to JavaScript

In the HTML page:

<script language="JavaScript">
function myJavaScriptFunction(input)
{
    window.alert(input);
}
</script>

ActionScript

import flash.external.ExternalInterface;
 
class ExternalInterfaceTest
{
    public function ExternalInterfaceTest()
    {
	if(ExternalInterface.available)
	{
        	ExternalInterface.call("myJavaScriptFunction", "Hello World");
	}
    }
    
}

Flash Lite authoring features in Flash Professional 8

The Flash Lite emulator and test window let you test your content as it will run and appear on an actual device. A settings pane in the Flash Lite test window lets you select a different test device, view information about your application, and set emulator debug output options.

flashlite_emulator.jpg

The Device Settings dialog box lets you select the test devices and Flash Lite content type that you want to test against in the Flash Lite emulator. Different devices support different modes of Flash Lite integration, or content types.

flashlite_devicesettings.jpg

The Property inspector contains a section that provides information about your current device settings as well as a button that lets you open the Device Settings dialog box (see the previous figure).

flashlite_propinspector.jpg

Device templates provide a starting point for you to create different types of Flash Lite content for different categories of devices.

Mysteries

There is several new things that are still undocumented, we’re looking for happy hackers to understand how they’re working :

MovieClip.prototype.scrollRect

- Can be used to define a viewing rectangle of a movie clip. The movieclip is cropped in the local co-ordinate space from its origin (0,0) to the specified with and height of the specified rectangle. You can then specify scroll offsets to move the content of the movie clip around inside the cropped area. This allows for very quick scrolling of text and complex vector data. To gain maximum performance, use scrollRect in conjunction with cacheAsBitmap, as the render can push around pixels alot quicker still.

MovieClip.prototype.transform

- An object which is an instance of flash.geom.Transform with properties pertaining to a movie clip’s matrix transformation (skew, x, y, rotation, scale), color transform, and pixel bounds, it has the following properties:

transform.matrix

- Instance of flash.geom.Matrix

transform.colorTransform

- Instance of flash.geom.ColorTransform

transform.concatenatedMatrix

- Instance of flash.geom.Matrix

transform.concatenatedColorTransform

- Instance of flash.geom.ColorTransform

MovieClip.prototype.scale9Grid

(also in Button.prototype) - The rectangular region that defines the nine scaling regions for the movie clip. If you’ve ever built a scalable button/box where the corners/edges were fixed and the middle was the only thing that “scaled”, you’ve created a scale9grid essentially. This allows you to define a rectangular area of a button/movieclip that will be the only area that scales when the object is scaled.

MovieClip.prototype.getRect

- Returns an object with properties that are the minimum and maximum x and y coordinate values of the movie clip, based on the bounds parameter, excluding any strokes on shapes. Returns an instance of flash.geom.Rectangle

BitmapData.loadBitmap

- You can now give bitmaps (png, jpg, gif) linkageID’s and with the BitmapData object, attach bitmaps to a movieclip:

var bd:BitmapData = BitmapData.loadBitmap("linkageID");
....
var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(bd, mc.getNextHighestDepth());

I suggest creating a movieclip container to attach to since there’s no other way to remove it later on other than removing the movieclip container it’s attached to.

And one KILLLLLER feature that will probably get a ton of use in some outstanding ways is copyPixels. The video jigsaw puzzle uses it in that it only drags the rectangle of pixles it needs for a given piece. Another use with FLV that I found EXTREMELY COOL, was filter compositing at runtime based on color information in the FLV playing back. I did a demo where I put a flat colored lightsaber (green 0x00ff00) in an FLV with alpha. Then, tracked the green color perframe, and applied a “glow” filter to the lightsaber - at runtime:

http://johngrden.blitzds.com/8ball/runtimeGlowCompositFLV.html

LEAD Technologies Inc. V1.01

The flash.external.ExternalData seems to be able to communicate with JavaScript and to encode/decode Flash values into XML.

Bugs

None at this moment with version 8,0,22,0

Community Submitted Examples

flashcoders/undocumented/flash8.txt · Last modified: 2007/10/30 09:26 by micros