close

Filter

loading table of contents...

Studio Developer Manual / Version 2010

Table Of Contents

7.7.3 Adding a Button with a Custom Action

The previous sections described how the predefined actions are wrapped in buttons and added to a toolbar. However, sometimes it is necessary to develop a custom action, for example to open a special window or to start a wizard. In Section 5.1.3, “Actions” you will find a more detailed explanation of actions, but the recipe shown here should be enough in many cases.

All actions inherit from ext.Action. For example, an action mypackage.MyCustomAction might look like this:

<?xml version="1.0" encoding="UTF-8"?>
<local:MyCustomActionBase
            xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:local="mypackage.*"
            xmlns:exml="http://www.jangaroo.net/exml/0.8"
            xmlns="exml:ext.config">
  <fx:Script><![CDATA[
    private var config:MyCustomAction;

    public native function MyCustomAction(config:MyCustomAction = null);
    ]]></fx:Script>
  <fx:Declarations>
  </fx:Declarations>

</local:MyCustomActionBase>

Example 7.38. Creating a custom action


It uses the complementing MyCustomActionBase class:

package mypackage {
import ext.Action;

public class MyCustomActionBase extends Action {
  public function MyAction(config:Action = null) {
    super(config);
  }
}
}

Example 7.39. Creating a custom action base class


You can access this class from ActionScript and (more commonly) from MXML. The name of the class determines the element name and its package is used as the namespace URI suffix:

...
<Button>
  <baseAction>
    <mp:MyCustomAction text="do something"/>
  </baseAction>
</Button>
...

Example 7.40. Using a custom action


For example, such a button with a base action might by added to the Favorites toolbar or the Actions toolbar as shown in the previous sections. The previous fragment assumes that you have defined the mp namespace so that it references the module containing mypackage (xmlns:mypackage.config).

Note that you can use all parameters inherited from ext.Action, like text in the example above.

Search Results

Table Of Contents