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.

Example:
Get domain we are in

var hostDomain:String = String(ExternalInterface.call("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.

CODE / HTML
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.

CODE / HTML
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
unicodeRangeU+0020-U+007E


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

































RangeValues
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.

Embedding Fonts Bug

When embedding fonts do not name fontName or fontFamily the filename or the text will not appear if you set TextField::embedFonts to true. The filename is probably the device font name which can only be used if TextField::embedFonts is false.

All variations produce the same results:
[Embed(source="C:/WINDOWS/fonts/ARIAL.TTF", fontFamily="Arial")]

[Embed(source="C:/WINDOWS/fonts/ARIAL.TTF", fontName="Arial")]

[Embed(source="C:/WINDOWS/fonts/ARIAL.TTF", fontFamily="Arial", mimeType="application/x-font-truetype")]

[Embed(source="C:/WINDOWS/fonts/ARIAL.TTF", fontName="Arial", mimeType="application/x-font-truetype")]

TextField::text
TextField::htmlText

Test:
[Embed(source="../assets/ARIAL.TTF", fontName="Arial")]
private const EMBED_ARIAL:Class;

var tf:TextField = new TextField();
var format:TextFormat = new TextFormat("Arial");
addChild(tf);

tf.embedFonts = true;
tf.defaultTextFormat = format;
tf.text = "Test";

OR

tf.embedFonts = true;
tf.text = "Test";
tf.setTextFormat(format);

You will see no text.

Fonts Bug

TextField::defaultTextFormat does not work with TextField::htmlText

var tf:TextrField = new TextField();
var format:TextFormat = new TextFormat("Arial");
addChild(tf);

Does not work:
tf.embedFonts = true;
tf.defaultTextFormat = format;
tf.htmlText = "Test";

Works:
tf.embedFonts = true;
tf.defaultTextFormat = format;
tf.text = "Test";

For TextField::htmlText use :
tf.setTextFormat(format);

Thursday, August 7, 2008

Command Line Debugger Shortcut

After you type "run" in the "(fdb)" command prompt and executed the SWF file to debug, the debugger will load the SWF code. Typing "info sources" or "info file" will bring a list of source files loaded. See the "#' on filename.as#1, well that is a shortcut to the file. Another way to find files and their number shortcut is to:

(fdb) list a

Will bring up all functions that begin with the letter "a" and what file they are in and yes it is case sensitive.

To set a break point simply type:

(fdb) break #19:315

The 315 being the line number you want to break at.
Not sure want line to break at?
List the file like so:

(fdb) list #19

This will list the first 10 lines of code. Repeatedly hitting enter executes the last command without the passed in argument, so it will list the next 10 lines and so on. To skip to a certain location try:

(fdb) list #19:75

Which will jump to the 75th line of code.
Type "continue" to run your SWF. Check out the other options be typing "help" on the "(fdb)" prompt.

Another shortcut that can be used is just typing the first few letters of the command and not the whole command. For example "c" for "continue", "r" for "run", and "b" for "break". "help" displays the shortcuts next to the command in parentheses.

Enjoy!