Monday, May 10, 2010

Add Events to Interfaces

Using the Event tag allows you to have events in Interfaces. With intellisense it will show a list of valid events when a method expects an event as a parameter, like the EventDispatcher::addEventListener method. They have to map exactly to each other.

[Event(name = "concrete string representation of event", type = "namespace to class with concrete instantiation")]

Comments in the interface override the comments in the concrete class when using the interface. Although you can specify the tag in the class it is customary to specify them after import declarations and before the class declaration.


Interface File:

  [Event(name = "some_event", type = "")]

  public interface IDo extends IEventDispatcher
    function doSomething():Boolean;

Class File:

  public class Do extends EventDispatcher implements IDo
    static public const SOME_EVENT:String = "some_event";
    public function doSomething():Boolean{ return true;}

Now when we use a method that expects an event; intellisense will display the options if you are using the interface.

Friday, April 16, 2010

Reparent AVM1 content in AVM2 (AS3) content.

For whatever reason you need to reparent loaded AVM1 content to another part of the display list and you don't want to keep the loader as the parent. One would have to save the content first from the LoaderInfo instance then use the LoaderInfo loader member to unload the loaded content.

You will then be allowed to reparent the saved content elsewhere. But be warned if you try to reparent it again you will get the:

"ArgumentError: Error #2180: It is illegal to move AVM1 content (AS1 or AS2) to a different part of the displayList when it has been loaded into AVM2 (AS3) content."

error as you would with the original. Remove the child first before you reparent.

Example from the Event.COMPLETE dispatch:
var li:LoaderInfo = as LoaderInfo;
var avm1:AVM1Movie = li.content as AVM1Movie;
var l:Loader = li.loader;

// No error

// No error

// Error #2180

Thursday, April 8, 2010

CS4 Class Paths

For reference:

C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\Component Source\ActionScript 3.0\User Interface

C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\First Run\Classes

C:\Program Files (x86)\Adobe\Adobe Flash CS4\Common\Configuration\ActionScript 3.0\projects\Flash\src

Tuesday, March 2, 2010

Execute Javascript in AS3 without it being on the host page...

One can have internal javascript functionality from within their SWF. We are passing the JS function to the browser to execute it. For this to work on the most popular browsers the object tag in HTML must have "allowscriptaccess='always'" and the object tag must have an id attribute in HTML for IE to work. And of course Javascript must be enabled for the browser to interpet and execute the given script.

Get domain we are in

var hostDomain:String = String("function(){ return document.domain;}"));

This returns the domain that loaded our SWF. They could be loading it from your server but serving it on their domain.

Saturday, December 5, 2009

Beware of browser zoom and SWF dimensions...

The browser feature to zoom web pages in and out, causes the dimensions of the hosted SWF to be modified. For example; the object tag might state 640x480 and at 100% those are the values you will get. If a user zooms at 125% those values will change to 800x600.

StageScaleMode.NO_SCALE / scale: "noscale"

this.stage.stageWidth x this.stage.stageHeight

IE fires an extra StageResize event, the 2nd event fired contains the modified dimensions for your SWF. Also the 1st ENTER_FRAME event contains the modified dimensions. Any reference before either of these results to dimensions of zero.

Firefox and Chrome give you the modified values from the beginning but no resize event unless resized after SWF loaded.

StageScaleMode.EXACT_FIT / scale: "exactfit"
StageScaleMode.SHOW_ALL / scale: "showall"
StageScaleMode.NO_BORDER / scale: "noborder"

The RESIZE event does not happen with these scale modes.

In IE one must rely on the ENTER_FRAME event to get the modified dimensions.

Firefox and Chrome give you the modified values from the beginning.

Currently the only way to get the intended dimensions are to pass them as flash vars. One could also call an External Interface function to get those values too.

Wednesday, October 22, 2008

Font Weight, Style, and Character Ranges

Valid attribute values for the Embed tag for fonts.

Attribute NameAttribute Values
fontStyleitalic | oblique | normal
fontWeightbold | heavy | normal

Unicode Ranges, which are just HEX values, can be split up.

Just Numbers [0..9]U+0030-U+0039
Punctuation, Numbers and SymbolsU+0020-U+0040
Upper-Case A-ZU+0041-U+005A
Punctuation and SymbolsU+005B-U+0060
Lower-Case a-zU+0061-U+007A
Punctuation and SymbolsU+007B-U+007E

Thursday, August 14, 2008

Embedding PFM / PFB fonts

If you embed a PFM you will get this compiler error:
"Error: exception during transcoding: Font for alias 'AdLibICG_Font' with plain weight and style was not found at:"

That is because PFM is a supporting font file, it does not contain the real data. PFB does.
You don't need the PFM font, just embed the PFB font.

[Embed(source="../assets/AdLibICG.PFB", fontName="AdLibICG_Font", mimeType="application/x-font-truetype")]
private const EMBED_ADLIBICG:Class;

You must prov
ide the mimeType or else this compiler error occurs:
"Error: '../assets/AdLibICG.PFB' does not have a recognized extension, and a mimeType was not provided"

More info on PFM/ PFB here.