*** 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).
Example
// 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) { this.onLoad(); }
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.