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!

Saturday, August 2, 2008

The Wheel

Always try to search for existing code, components, and libraries before venturing out to developer land.

Components
MinimalComps
Great for prototyping.

Yahoo! Astra

They actually have a lot of useful information.


Libraries
AS3CoreLib
Documentation
Contains a lot of useful functionality.

AS3Crypto

All crypto, all the time!

Alternative Crypto
labs.boulevart.be (A variety of encryption)
gsolofp.blogspot.com (MD5 and SHA1)


Occasionally Updated...

Thursday, July 31, 2008

Using Components in Flash Develop

To use Flash IDE components in Flash Develop:

  1. Create a new 'Flash File'

  2. Double click on the components you want to use. (Ctrl + F7 to bring up the 'Components' window)

  3. Select a component in the 'Library' window and select 'Export to SWC...'

  4. Decide on a file name and save it


It does not matter which component you choose, it will all be added to the created SWC. Now just make sure to add it for inclusion when you build your code, which ever way you do it.

To double check if the components are there just open the SWC file with a zip program and you should see a list of SWFs and catalog.xml file.

Installing Flex 3 and Ant

Ant install:
Unzip "apache-ant-1.7.1-bin.zip"
into "C:\Program Files\"

Flex 3 SDK install:
Unzip "flex_sdk_3.zip" into "C:\Program Files\flex_sdk_3"

Copy the "C:\Program Files\flex_sdk_3\ant\lib\flexTasks.jar" into
"C:\Program Files\apache-ant-1.7.1\lib\"

Access the environment variables:
(Windows Key + Pause)
Go to the "Advance" tab then the "Environment Variables" button.

Create Environment Variables:
Create new variables called:

ANT_HOME
FLEX_HOME

With values of, respectively:

C:\Program Files\apache-ant-1.7.1
C:\Program Files\flex_sdk_3

Add to your path:
%ANT_HOME%\bin;%FLEX_HOME%\bin

Setup Flash Develop:
We have to tell Flash Develop where to look for the compiler.

Either hit F10 or traverse to Tools::Program Settings...
Select "AS3Context" on the left pane under "Plugins".
Under "Language" in the right pane, select and modify "Flex SDK Location".

For the purpose of this post it is "C:\Program Files\flex_sdk_3".

Under Project::Properties...
Select the "Output" tab.
Check the check box of "No output, only run pre/post build commands."

Select the "Build" tab.
Under the "Pre-Build Command Line" section add "ant.bat".
This is why we need the ANT_PATH variable.
Apply the changes.

When working on a project you ideally would have a "build.xml"
file in the root of your project. To build the project hit F8. This
will produce whatever the build file was told to do.

The FLEX_PATH allows ant to access mxmlc and compc executables.
Flex Tasks allows us to add compiler options as xml nodes. More on that here.

Wednesday, July 16, 2008

Command Line Compiler and Debugger

Open a command prompt here:
C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0

Compiler

java -jar asc_authoring.jar -help

Debugger:

java -jar fdb.jar

Which will get you this:
(fdb)

Then type "help" or "tutorial".

Enjoy!

More later.

Thursday, June 26, 2008

JSFL Command Path

I have to add JSFL files to this post. Will try to use skyDrive from MS.

C:\Program Files\Adobe\Adobe Flash CS3\en\First Run\Commands

C:\Documents and Settings\YOUR_USERNAME\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Commands

Thursday, May 29, 2008

Default Class Paths

Auto-completion is nice. The less typing done, the less chance of bugs.

Use these paths to point to Adobe's code, so Flash Develop knows where to look.
Ctrl + F9 to open up Global Paths.
Choose AS3 in the drop down menu.
Copy and paste away.

C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Component Source\ActionScript 3.0\User Interface\

C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\Classes

C:\Program Files\Adobe\Adobe Flash CS3\en\First Run\Classes

Thursday, February 7, 2008

Getting Strict with Compilation

Want better runtime warnings?
Check out the file "EnabledWarnings.xml".

It lives here on a Windows machine:

C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\ActionScript 3.0\

I like to enable the first three under this comment:
"<!-- Coding style preference warnings. Use these warnings if you want to be reminded to always use type declarations, acess/namespace attributes, etc. -->"

I wonder if adding a file called EnabledErrors.xml would work?

Sunday, February 3, 2008

Errors 5003 & 5005

I have to add some proof of concept files to this post. Will try to use skyDrive from MS.

Error Code 5005
Error Code 5003

These numbers mean it time to refactor.

"5003: Unknown error generating bye code."

"5005: Unknown error optimizing byte code"

They both stem from the same problem. Flash not knowing how to handle
an "Out Of Memory" error exception from Java from the (asc_authoring.jar) file. You can see this if you try
to build in Flex.

This happens when there is just too much code for it to handle with the default memory space of 128MB.

If you ever compile a SWF and just get a blank screen it could be because the SWF does not contain any of your code.

To verify this look at your generated size report file from the Flash IDE. The section which says "actionscript code bytes" will be about 16 bytes. The SWF does not know where to jump to execute your code because it has not been inserted into the SWF

This could be fixed by specifying -Xms and -Xmx command line arguments when compiling the SWF with the asc_authoring.jar file.

Unfortunately, you can't do this in the Flash IDE. I have modified the asc_authoring.jar file to see if I can actually save the parameters used in the build, so that we can use the command line with the appropriate memory setting but so far I have been unsuccessful.

Adobe support was no help with this matter. They are pretty clueless of this from my experience with them.

Temporary ways of dealing with this:
  1. Delete ASO files
  2. Comment out all trace statements.
  3. Uncheck “Reduce File Size and increase performance” in AS3 settings
  4. Create a singleton class with static empty classes that get filled in at runtime (Bridge Pattern).

Other sites mentioning these errors:
  1. www.kirupa.com
  2. www.negush.net
  3. www.ultrashock.com
Settled on solution:
Moving over to Flex and using Ant to build will resolve this error if you use the environment variable ANT_OPTS with the correct memory requirements for the build.

Saturday, February 2, 2008

Tools

The developer, in accordance with his aims, uses various tools and knows their characteristics and uses them well. This is the way of the developer.

We all know this. So I share the tools I use for compiling, debugging, finding, testing, etc.

Freeware Windows Based Tools:
Design
FreeMind to map your ideas out.
UMLPad to diagram class, state, etc. models.

Compiling
Flash Develop code editor.
Flex SDK compiler to be used in Flash Develop.
ANT is a java based build tool that uses XML for build scripts.

Debugging
Flash Debug Players to see trace statements with Flash Tracer, FDB, or in the output pane of Flash Develop.
Fiddler to sniff communications if your making HTTP requests.
WireShark sniff all other communications.
Flash Tracer to get traces when a SWF is deployed from inside a html browser.

Version Control
Tortoise SVN to save versions as your code progresses.
WinMerge to compare versions for text, files, and folders.

V0.0

This blog will consist of the adventures I have had developing in Flash CS3 and AS3.