when i’m coding directly on the timeline, i usually create a var like this:
var home:MovieClip = this;
so i always have something to reference the main timeline’s scope. how could i do this in a class? delegate.create gets a little confusing.
i tried a few things like the following:
class com.myClass
{
public var className:String = "myClass";
public static var version:String = "0.0.1";
private static var instance:myClass;
public function myClass()
{
init();
}
//
private function init():Void
{
instance = this;
trace(instance);
trace(typeof(instance));
}
}
/* output:
Class: newsXML, Version: 0.0.1
object
*/
i was surprised that the first line of output actually listed the class name and version instead of [type, Object], but i guess ‘className’ and ‘version’ are recognizable variables? i’m new to writing classes, and coding in general.
but back to the main point, why couldn’t i do the following:
private function init():Void
{
instance = this;
xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = instance.someFunction; // instead of Delegate.create(this, someFunction);
xml.load("any.xml");
}
//
private function someFunction():Void
{
trace("someFunction();");
trace("xml == " + xml);
}
someFunction() never fires, and the xml doesn’t load. how would this work? is it redundant? i can’t figure out what i’m missing here, when the following does work:
private function init():Void
{
instance = this;
xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = Delegate.create(this, checkXML);
xml.load("any.xml");
}
//
private function checkXML():Void
{
if(xml.loaded == true)
{
trace("XML loaded");
instance.parseNews(); // this scoping works?????????
}
else
{
trace("error loading XML");
}
}
//
private function parseNews():Void
{
trace("parseNews();");
trace("xml == " + xml);
}
of course this is redundant because it’ll scope just fine as parseNews();, but i’m just wondering why it’s letting me scope it like this here and not in the onLoad declaration?
thanks for your help.