next up previous contents
Next: Playing avi, rm, mov, Up: Tutorials Previous: Screen capture   Contents

Reusing the web browser control

You can embed the web browser control in the main movie or forms to display web sites or web pages. In fact, the createControl method in SWFKit and SWFKit Pro can embed any ActiveX control in the main movie. First, you would have to call the "createControl" method to create the ActiveX control window and embed it in the main movie. The method will returns an object, which has two properties, one is "window", a Window object that represents the ActiveX control window, and the other is "activex", an ActiveXObject object that can be used to access the methods and properties of the ActiveXControl. To reuse the web browser control, the code in FFish script would be
// Create the web browser control
var ax = createControl("Shell.Explorer.2", 0, 0, 200, 200);
// Fill the web browser control in the entire client area of the main window
getMainWnd().onSize = function(type, width, height)
{
    ax.window.move(0, 0, width, height);
}

// handle event of the ActiveX control
ax.activex.NavigateComplete2 = function (control, url)
{
    trace(url);
}

// Browse web site
// The ActiveXObject accepts case insensitive method names.
// Please be careful that both FFish script and Action script
// are case sensitive
ax.activex.navigate2("http://www.topcmm.com");

Although you can also write code in action script to embed a web browser control, you would have to wrap the web browser control in an Action script class, because Action script does not allow you to call a dynamic method that is not defined in a class. A sample wrapper class, "WebBrowser.as", which defines only one method of the web browser, is as follows

    import SWFKit.*;
    import flash.external.*;

    class WebBrowser extends SWFKit.ActiveXObject
    {
        public function WebBrowser(progID)
        {
            super(progID);
        }

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

            return ax;
        }

        public function Navigate2()
        {
            return ExternalInterface.call("ffish_call2", this.Identifier,
                                          "Navigate2", arguments);
        }

        // the other methods ...
    }
The following code shows how to use the web browser in action script in Flash 8
    import SWFKit.*;
    import WebBrowser;

    // Create the web browser control
    var ax = Global.createControl("Shell.Explorer.2", 0, 0, 200, 200);
    // Fill the web browser control in the entire client area of the
    // main window
    var win = Global.getMainWnd();
    ax.window.move(0, 0, win.clientRect.width, win.clientRect.height);
    function onSize(type, width, height)
    {
        ax.window.move(0, 0, width, height);
    }
    win.setEventHandler("onSize", onSize);

    var wb = WebBrowser.fromID(ax.activex);
    // handle event of the ActiveX control
    function NavigateComplete2(control, url)
    {
        _root.strace(url);
    }
    wb.setEventHandler("NavigateComplete2", NavigateComplete2);

    // Browse web site
    wb.Navigate2("http://www.topcmm.com");

To learn how to embed an ActiveX control in a form, please read the "Creating multiple forms" tutorial.

The reference of reusing the web browser can be found at here


next up previous contents
Next: Playing avi, rm, mov, Up: Tutorials Previous: Screen capture   Contents
Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.