convert swf to exe, make flash application, flash to exe, make flash screensaver, swf to exe, swf to mp3
 
Products: SWFKit Pro, SWFKit, SWFKit Express | SWFKit Online | SWFSnd | SWFImg | SWFGen | 123FlashChat | MingX
  Home > Products > SWF Kit Series > Tutorials > Using SWFKit Series 3 Objects in Flex Builder 2
Overview Features Comparison Samples Download Buy Now Tutorials Documentation
 

10. Using SWFKit Series 3 Objects in Flex Builder 2

With the FFish Script wrapper classes for ActionScript 3, you can use SWFKit Series 3 objects directly in Flex Builder 2. That is, instead of calling ffish scripts asynchronously by using fscommand, you now can use the FFish Script objects synchronously and directly in ActionScript 3, just like calling any native object of ActionScript 3. The FFish Script wrapper classes can be downloaded at here. This tutorial will guide you into the way of using SWFKit Series 3 objects in Flex Builder 2 step by step.

Adding the wrapper classes into the source path of the Flex project

Before you can use the FFish Script objects in a Flex project, you must first add the wrapper classes into the its source path. This must be done in the project properties dialog box in Flex Builder 2, as shown in the following image:

The project properties dialog box can be launched by clicking the "Properties" item of the "Project" menu in Flex Builder 2. After launching the dialog box, you can select the "Flex Build Path" item and add the path of the wrapper classes into the source path of the project.

Writing code in Flex Builder 2 to call the FFish Script objects

Each FFish Script object has an ActionScript 3 wrapper class through which you may access the properties and methods of the FFish Script object. For example, the following code is the wrapper class for the "Dialogs" object:

package SWFKit {
import flash.utils.Proxy;
import flash.utils.flash_proxy;
import flash.external.*;

public dynamic class BaseObj extends Proxy {
public var Identifier: Number;

public function fnBaseObjByName(objName:String):void {
var ret:* = ExternalInterface.call("ffish_new", objName);
if (ret == null || ret == undefined) this.Identifier = 0;
else this.Identifier = ret;
}

public function fnBaseObjByID(id: Number):void {
this.Identifier = id;
}

override flash_proxy function callProperty(methodName:*, ... args):* {
return ExternalInterface.call("ffish_call2", this.Identifier,
String(methodName), args);
}

override flash_proxy function getProperty(name:*):* {
return ExternalInterface.call("ffish_getprop", this.Identifier,
String(name));
}

override flash_proxy function setProperty(name:*, value:*):void {
ExternalInterface.call("ffish_setprop", this.Identifier,
String(name), value);
}

public function IsValid(): Boolean
{
return this.Identifier != 0;
}

public function Release(): void
{
ExternalInterface.call("ffish_delete", this.Identifier);
}

public function setEventHandler(event: String, handler:Function):void
{
var handlerName:String = "_" + this.Identifier + "_" + event;
ExternalInterface.addCallback(handlerName, handler);
ExternalInterface.call("ffish_seh", this.Identifier, event, handlerName);
}

public function getObject():Object {
var obj:Object = new Object;
obj.Identifier = this.Identifier;
return obj;
}
}
}

package SWFKit {
public dynamic class Dialogs extends BaseObj {
public function Dialogs() {
super.fnBaseObjByName("Dialogs");
}
}
}

 

where the "BaseObj" class is the base class of all the wrapper classes, which provides the ability of dynamically accessing properties and methods of every FFish Script object. The following code shows how to use the "Dialogs" object in Flex Builder 2:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button x="180" y="286" label="Button" id="MyBtn" click="OnClickMyBtn()"/>
<mx:Script>
<![CDATA[
import SWFKit.*;

private function OnClickMyBtn():void
{
var d:Dialogs = new Dialogs;
var fileName:* = d.fileOpen("All files(*.*)|*.*");
if (fileName)
{
d.msgBox(fileName);
}
}
]]>
</mx:Script>
</mx:Application>

The above sample launches a file open dialog box when click the button. If a file is selected, it will display a message box to show the selected file name.

If you want to handle the events of the FFish Script objects, please use the "setEventHandler" method of the wrapper classes. The following sample shows how to add a systray icon and handle the mouse clicks:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Button x="180" y="286" label="Button" id="MyBtn" click="OnClickMyBtn()"/>
<mx:Script>
<![CDATA[
import SWFKit.*;
import SWFKit.application.*;

private var st:SysTray = new SysTray;

private function st_onLClicked ():void
{
st.balloonTip = "Happy New Year!";
st.balloonTitle = "Hello";
st.balloonIcon = "warning";
st.showBalloonTip();
}

private function st_onRClicked ():void
{
var menu:Menu = new SWFKit.Menu;
menu.createPopupMenu();
menu.appendItem("id0", "item 0", "525flop1.ico");
menu.appendItem("id1", "item 1", "audio.ico");
menu.appendItem();
menu.appendItem("id2", "item 2", "cddrive.ico");
menu.appendItem("id3", "item 3", "clsdfold.ico");

Global.getMainWnd().bringToTop();
Global.trace(menu.show());
}

private function OnClickMyBtn():void
{
st.useDefaultHandler = false;
st.setEventHandler("onRClicked", st_onRClicked);
st.setEventHandler("onLClicked", st_onLClicked);

st.icon = Global.getAdditionalFile("audio.ico");
st.tip = "A test";
st.add();
}
]]>
</mx:Script>
</mx:Application>

 

Some method of the FFish Script objects may has an object type argument, for example, the "write" method of the "RegKey" object, its only argument must be a RegValue object. In this case, you should use the "getObject" method of the wrapper classes to pass parameters. For example:

var rk:RegKey = new RegKey("HKCU\\Software\\xxxx\\xxxx");
var rv:RegValue = new RegValue;
rv.name = "name";
rv.data = "value";
rv.type = 2;

// Note: you should use "getObject" at here, or "rk.write(rv);" doesn't work
rk.rite(rv.getObject());

In ActionScript 3, you no longer need wrapper classes for ActiveX components, that is, you can access the properties and methods of the ActiveX components directly using the "ActiveXObject" class.

 

Link to us

Contact us

Feel free to link to us!
We appreciate it!

support@swfkit.com
sales@swfkit.com
info@swfkit.com

Bookmark our site Tell a friend, Win a CD Flash Chat in China