next up previous contents
Next: Differences between wrapper classes Up: Using FFish script objects Previous: How does the synchronous   Contents

Wrapping ActiveX components

Each ActiveX component has its own property and method set, and Action script classes do not support to add methods dynamically, so you would have to wrap ActiveX components by yourself. We have already created a base class - SWFKit.ActiveXObject, although it has methods to access properties or methods of an ActiveX component, it is not so convenient and distinct:
import flash.external.*;

class SWFKit.ActiveXObject extends SWFKit.BaseObj
{
    public function ActiveXObject(progID)
    {
        if (progID == null)
        {
            this.Identifier = 0;
        }
        else
        {
            var ret = ExternalInterface.call("ffish_new", "ActiveXObject", progID);
            if (ret == null || ret == undefined) this.Identifier = 0;
            else this.Identifier = ret;
        }
    }

    public static function fromID(id: Number)
    {
        var ax = new ActiveXObject(null);
        ax.Identifier = id;

        return ax;
    }

    public static function register(filename: String)
    {
        return ExternalInterface.call("ffish_call", "ActiveXObject", "register");
    }

    public static function unregister(filename: String)
    {
        return ExternalInterface.call("ffish_call", "ActiveXObject", "unregister");
    }

    public function getProperty(prop: String)
    {
        return ExternalInterface.call("ffish_getprop", this.Identifier, prop);
    }

    public function setProperty(prop: String, value)
    {
        ExternalInterface.call("ffish_setprop", this.Identifier, prop, value);
    }

    public function callMethod()
    {
        var args = arguments;
        if (args.length >= 1)
        {
            var argForFFish = new Array();
            var i;
            for (i = 1; i < args.length; i++)
                argForFFish.push(args[i]);
            return ExternalInterface.call("ffish_call2", this.Identifier,
                                          args[0], argForFFish);
        }

        return undefined;
    }
}

To wrap an ActiveX component, you would have to inherit this class. For example, wrapping a method of the Flash Player activex control.

import flash.external.*;
import SWFKit.*;
class FPActiveX extends SWFKit.ActiveXObject
{
    public function FPActiveX(progID)
    {
        super(progID);
    }

    public function FlashVersion()
    {
        return ExternalInterface.call("ffish_call", this.Identifier,
                                      "FlashVersion");
    }
}
To call it
    var fp = new FPActiveX("ShockwaveFlash.ShockwaveFlash");
    _root.strace(fp.FlashVersion());



Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.