ActionScript vs. Objective C

If you are interested in Objective C programming this article a good start to explore:
Cocoa Chronicles #1: ActionScript vs. Objective C

Posted in ActionScript, iPhone / iPad, Mac | Leave a comment

FFK10 – Flashforum conference notes

Every year I spend two days sitting in the audience of the Flashforum conference (FFK) listening to great speakers and getting impressed by their experiments and thoughts. It’s also a good way to renew some of the basic knowledge in Flash development and of course to meet some friends in the Flash scene.

So this are most of my notes:

Flash / Flex development:

  • Jessee Freemans Flash Augmented Reality Debug Tool provides an easy way to start with augmented reality development.
  • Use stunning Hype-Framework effects.
  • Dive into dynamic sound generation with André Michelles Audio-Sandbox.
  • Have a look at the PushButton-Engine for component based development.
  • Remember that Flex 4 includes a lot of performance features! It’s highly recommended to switch as soon as possible. For example the Embed-tag reduces PNG file size and lots of improvements are made within the Flex components.
  • Watch the Adobe TV video preview: Flex for mobile devices
  • See Christian Cantrell’s blogpost One Application , Five Screens (Including the iPad)
  • Great tip: ByteArray.org – Why cacheAsBitmap is bad
  • Adobe’s Mobile Development Guide for the Flash platform (applies also to desktop applications) contains performance tips like:

    • DisplayObject.width / height should be divisible by 2 as often as possible
    • Try to avoid Events and / or stop propagation as soon as possible
    • Set DisplayObject.mouseEnabled=false if possible
    • Stop MovieClip animations when removed from stage
    • Use TextField.opaqueBackground=true if possible
    • Use final statement (final class ClassName {})
    • Use BitmapData.get / setVector()

HTML / JavaScript basics:

  • Use “Sprites” with HTML / CSS (load only one bitmap graphic containing all the asset images for your page and show only the particular relevant parts) and preload next page assets using AJAX while your current page is idle.
  • Since usually only 2 simultaneous domain http requests are supported by browsers it’s a good practice to distribute contents from various ip addresses (use asset-servers for example).
  • Load only visible parts of your site using JavaScript viewport events.

Useful workflow utils:

Posted in ActionScript, AIR, Flash, Flash in Browser, Flash Player, Flex, How To..., iPhone / iPad, Librarys, Utils | 3 Comments

Embed fonts with Adobe Flash IDE

Almost every Flash project needs some embedded fonts and it is a good practice to compile the fonts into a separate SWF file. So here is a simple way to create a file that contains only embedded fonts. The SWF file will also show the exact internal font names:

  1. Copy and paste the ActionScript code below into the first keyframe of your timeline.
  2. Create new fonts in flash library and export them for ActionScript.
    A good tutorial can be found here.
  3. Run ONLY the code for step 2 to evalute and trace the exact font names.
  4. Assign the exact font names to the actual library symbols and their export class name.
  5. Run ONLY the code for step 4 to export the swf.
Security.allowDomain( "*" );
 
// Step 1: Create new fonts in flash library
//         and select "Export for ActionScript".
 
 
// Step 2: Run ONLY this code to evalute and trace the exact font names.
/**/
var embeddedFonts : Array = Font.enumerateFonts ( false );
var c : uint = embeddedFonts.length;
for ( var i : uint = 0; i < c; i++ )
{
    var font : Font = embeddedFonts[ i ] as Font;
    var className : String = font.fontName.split( " " ).join( "" );
 
    var lowerFontStyle : String = font.fontStyle.toLowerCase();
    if ( lowerFontStyle.indexOf( "bold" ) != -1 ) className += "Bold";
    if ( lowerFontStyle.indexOf( "italic" ) != -1 ) className += "Italic";
 
    trace( className );
}
/**/
 
// Step 3: Assign the exact font names to the actual
//         library symbols and their export class name.
 
 
// Step 4: Export the swf using ONLY this code. 
/**/
var posX : int = 10;
var posY : int = 10;
 
var embeddedFonts : Array = Font.enumerateFonts ( false );
    embeddedFonts.sortOn( "fontName", Array.CASEINSENSITIVE );
 
var c : uint = embeddedFonts.length;
for ( var i : uint = 0; i < c; i++ )
{
    var font : Font = embeddedFonts[ i ] as Font;
 
    var lowerFontStyle : String = font.fontStyle.toLowerCase();
 
    var textFormat : TextFormat = new TextFormat();
        textFormat.bold = ( lowerFontStyle.indexOf( "bold" ) != -1 );
        textFormat.italic = ( lowerFontStyle.indexOf( "italic" ) != -1 );
        textFormat.font = font.fontName;
        textFormat.size = 14;
 
    var className : String = font.fontName.split( " " ).join( "" );
    if ( textFormat.bold ) className += "Bold";
    if ( textFormat.italic ) className += "Italic";
 
    Font.registerFont( Class( getDefinitionByName( className ) ) );
 
    var boldItalic : String = "";
    if ( textFormat.bold && textFormat.italic )
    {
        boldItalic = "( needs to be BOLD and ITALIC ! )";
    }
    else if ( textFormat.bold )
    {
        boldItalic = "( needs to be BOLD ! )";
    }
    else if ( textFormat.italic )
    {
        boldItalic = "( needs to be ITALIC ! )";
    }
 
    var textField : TextField = new TextField();
        textField.autoSize = TextFieldAutoSize.LEFT;
        textField.defaultTextFormat = textFormat;
        textField.embedFonts = true;
        textField.text = font.fontName + "\t" + boldItalic;
        textField.x = posX;
        textField.y = posY;
 
    posY += textField.height + 5;
 
    addChild( textField );
}
/**/

Posted in ActionScript, Flash, How To... | Leave a comment

Flash Player Security

Just some helpful links:
Understanding the security changes in Flash Player 10
Policy file changes in Flash Player 9 and Flash Player 10

Posted in Flash, Flash in Browser, Flash Player | Leave a comment

Flash and Amazon SimpleDB

I did some research about using Amazons SimpleDB service within a Flash based application and found these basic facts:

  • http://sdb.amazonaws.com/crossdomain.xml is not available. This means no direct calls from Flash clients in browsers are possible!
  • Even if it would be possible some day, you would need to find a secure way to deliver your AWS key to the Flash client.
  • Using a web proxy is a solution that would cause a lot of traffic on your server.

So using Amazons SimpleDB for browser based Flash applications makes not much sense to me.
It might be more useful for Flash applications running on local machines like Flash projectors or Adobe AIR applications but there is still a security problem with hiding your AWS key.

Anyway, I found two ActionScript libraries that might be useful:
http://code.google.com/p/actionscript-simpledb-library/
http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1365

And this thread in Amazons discussion forums:
http://developer.amazonwebservices.com/connect/thread.jspa?threadID=19698

Posted in AIR, Flash, Flash in Browser, Flash Player, Flex, Librarys, Server | 1 Comment

URLRequest with HTTP authentication

I found a good explanation how to support HTTP authentication with URLRequests here.

That’s the most interesting part:

Best I can tell, for some reason, this only works where request method is POST; the headers don’t get set with GET requests.

Interestingly, it also fails unless at least one URLVariables name-value pair gets packaged with the request, as indicated above. That’s why many of the examples you see out there (including mine) attach “name=John+Doe” — it’s just a placeholder for some data that URLRequest seems to require when setting any custom HTTP headers. Without it, even a properly authenticated POST request will also fail.

You’ll almost surely have to modify your crossdomain.xml file to accommodate the header(s) you’re going to be sending. In my case, I’m using this, which is a rather wide-open policy file in that it accepts from any domain, so in your case, you might want to limit things a bit more, depending on how security-conscious you are:

<?xml version="1.0"?>
<cross-domain-policy>
    <allow-access-from domain="*" />
    <allow-http-request-headers-from domain="*" headers="Authorization" />
</cross-domain-policy>

… and that seems to work; more information on this one is available from Adobe here).

Apparently, Flash player version 9.0.115.0 completely blocks all Authorization headers (more information on this one here), so you’ll probably want to keep that in mind, too.

So this little code snippet explains the basics:

// Base64Encoder contained in Flex SDK
import mx.utils.Base64Encoder;
 
// Encode username and password
var base64Encoder : Base64Encoder = new Base64Encoder();        
    base64Encoder.encode( "username:password" );
 
// Create authorization request header
var urlRequestHeader : URLRequestHeader = new URLRequestHeader( "Authorization", "Basic " + base64Encoder.toString() );
 
// URLRequest setup
var urlRequest : URLRequest = new URLRequest( "url" );        
    // Needs to send some data!!        
    urlRequest.data = new URLVariables( "name=John+Doe" );        
    // Only supported with POST method!!        
    urlRequest.method = URLRequestMethod.POST;        
    // Apply authorization request header        
    urlRequest.requestHeaders = new Array( urlRequestHeader );

Posted in AIR, Flash, Flash in Browser, Flash Player, How To... | Leave a comment

DisplayObject.rotationX,Y,Z

Just a quick note about working with DisplayObject.rotationX,Y,Z:

Keep in mind that your DisplayObject rotates around it’s center point. This may result in weird optics if you forget to align your DisplayObject properly.

Update: Well, there is much more to know!

There’s need for an DisplayObjectContainer with an properly assigned PerspectiveProjection.

Copy & paste this code and you’ll see what I’m talking about:

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener( Event.RESIZE, onStageResize );
 
function onStageResize( event : Event ) : void
{
    draw();
}
 
function createRectSprite( w : int, h : int, rotationY : Number, container : Sprite, useProjection : Boolean ) : Sprite
{
    // 3D object
    var graphicSprite : Sprite = new Sprite();
        graphicSprite.name = "graphicSprite";
        graphicSprite.rotationY = rotationY;
        graphicSprite.buttonMode = true;
        graphicSprite.useHandCursor = true;
 
    // Make sure 3D objects content is centered
    var g : Graphics = graphicSprite.graphics;
        g.beginFill( 0, .5 );
        g.drawRect( w * -.5, h * -.5, w, h );
        g.endFill();
 
    // 3D Container
    var containerSprite : Sprite = new Sprite();
        containerSprite.addChild( graphicSprite );
 
    // Apply projection to 3D Container instead of 3D Object
    if ( useProjection )
    {
        var projection:PerspectiveProjection = new PerspectiveProjection();             
            projection.projectionCenter = new Point( 0, 0 );
 
        containerSprite.transform.perspectiveProjection = projection;
    }
 
    // Visualize center
    g = containerSprite.graphics;
    g.beginFill( 0xff0000 );
    g.drawCircle( 0, 0, 2 );
    g.endFill();
 
    container.addChild( containerSprite );    
    return containerSprite;
}
 
var left : Sprite;
var right : Sprite;
 
function draw() : void
{
    while ( numChildren > 0 ) { removeChildAt( 0 ); }
 
    var container : Sprite = new Sprite()
        container.name = "container";
        container.x = stage.stageWidth * .5;
        container.y = stage.stageHeight * .5;
    addChild( container );
 
    var stepX : int = stage.stageWidth / 3;
 
    var w : int = 200;
    var h : int = 200;
 
    left = createRectSprite( w, h, -60, this, true );
    left.name = "left";
    left.x = stepX;
 
    right = createRectSprite( w, h, 60, this, true );
    right.name = "right";
    right.x = stepX * 2;
 
    left.y =
    right.y = stage.stageHeight * .5;
}
 
function onEventHitTest( event : Event ) : void
{
    var containerSprite : DisplayObjectContainer;
    var graphicSprite : DisplayObject;
 
    containerSprite = this.getChildByName( "left" ) as DisplayObjectContainer;
    graphicSprite = containerSprite.getChildByName( "graphicSprite" ) as DisplayObject;
 
    trace( "hit left containerSprite:", containerSprite.hitTestPoint( mouseX, mouseY, true ) );
    trace( "hit left graphicSprite:", graphicSprite.hitTestPoint( mouseX, mouseY, true ) );
 
    containerSprite = this.getChildByName( "right" ) as DisplayObjectContainer;
    graphicSprite = containerSprite.getChildByName( "graphicSprite" ) as DisplayObject;
 
    trace( "hit right containerSprite:", containerSprite.hitTestPoint( mouseX, mouseY, true ) );
    trace( "hit right graphicSprite:", graphicSprite.hitTestPoint( mouseX, mouseY, true ) );
    trace( "" );
}
 
stage.addEventListener( MouseEvent.MOUSE_DOWN, onEventHitTest );
 
draw();

Posted in ActionScript, Flash | 2 Comments

ActionScript 3 API Reference for the iPhone

http://www.mikechambers.com/as3iphone/

Nice to have!

Posted in ActionScript, Documentations, Flash, Flex, iPhone / iPad | Leave a comment

Mac – Local Server Development Basics

Since I had to figure out some basics about local server development on my Mac, I really recommend these tools:

  • MAMP – Apache and MySQL Server
  • Virtual Host X – Create up to 3 virtual host with the free version.
    In other words: This provides an easy to use GUI which enables you to forward an local URL like “http://myProject.local” to your workspace directory.

But one thing sucks: You have to set read/write access (in finder) for everyone. I wonder if that might cause system security problems?

And I strongly recommend to read this nice tutorial about setting up virtual hosts manually: http://www.sawmac.com/mamp/virtualhosts/

Posted in Mac, Server | Leave a comment

Blocking Flash in Safari

Firefox users probably know the Flashblock plugin and I just want to note a link to a similar plugin for webkit which works well with Safari.

http://rentzsch.github.com/clicktoflash/

Posted in Flash in Browser | Leave a comment