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.

Example:

Interface File:
package com.site
{
  import flash.events.IEventDispatcher;

  [Event(name = "some_event", type = "com.site.Do")]

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

Class File:
package com.site
{
  import flash.events.EventDispatcher;

  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 = e.target as LoaderInfo;
var avm1:AVM1Movie = li.content as AVM1Movie;
var l:Loader = li.loader;
l.unload();

// No error
layer1.addChild(avm1);

// No error
layer1.removeChild(avm1);
layer2.addChild(avm1);

// Error #2180
layer3.addChild(avm1);

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.

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.