Zinc’s Browser & Hacking _root

*** Updated 7.7.2005 ***

Zinc allows you to have a browser appear over top of your Flash movie so you can make an interactive web browser. However, Zinc’s programming model assumes AS2 classes don’t exist and _root is… well, just like everyone views _root; as their playground, putting anything they want there and assuming it won’t change.

What we do is something Darron Schall showed me, only a little different. It allows us to treat _root as a class, get syntax checking, and emulate what Flex does with “mx.core.Application”. We override _root’s __proto__ so it points to our Singleton class, call its constructor manually, and call onLoad if it hasn’t been called already. I had to put a conditional for onLoad because sometimes it gets called for you, and sometimes it doesn’t (like when you debug in Flash).


// ensures Flash/MTASC compiles class
import com.Application;
var depend:Application;
delete depend;

// override _root's proto
this.__proto__ = _global.com.com.Application.prototype;
//call constructor
_global.com.Application.apply(this, null);
// call onLoad if it hasn't been called already
if(this.calledOnLoad == false)

That, however, pisses Zinc off. We have do store a reference to the Browser’s class instance on _root (Application class) so it knows to forward events it gets such as when a webpage is done downloading in the browser(in this case, “onBrowserDocumentComplete”). However, after doing the above _root.__proto__ override, I no longer receive those events. It seems the _root Zinc thought was there is no longer there, even though I can clearly trace out the funciton it needs as there and available. Making it static doesn’t work either. However, putting this in the constructor does:

this.onBrowserDocumentComplete = this.onBrowserDocumentComplete2;

Where the “onBrowserDocumentComplete2” is the class method, and onBrowserDocumentComplete is merely a variable you define up top:

public var onBrowserDocumentComplete:Function;

Something about _root’s “instance” is what Zinc likes I guess. Anyway, I now get my _root events again from Zinc.

5 Replies to “Zinc’s Browser & Hacking _root”

  1. Hi Jesse,
    I recently did a review for 6 of the major projector tools: http://www.flashmagazine.com/1100.htm What I found was that mProjector is that tool that works the most like I want such a tool to work. It works from within any AS2 class without troubles and most commands require no callback handlers, they rather return results instantly. Ultra-smooth development, but fewer commands than Zink. It’s also slightly slower than Zink for processor intensive tasks.

  2. Guess I focused too much on you having to resort to hacks to make Zink work with AS2. mProjector does not require that, but it also has no way to control a browser (among other things) like you apparently need, so it’s no solution either… :(

  3. I own _root. I am become _root. _root is all and all is _rooted. _root will have its revenge.

  4. Hey man,

    Haven’t had a chance to play around with it but have you tried calling mdminit after you declare your _root class?

    If that doesn

Comments are closed.