That insanely smart Canuck (at least, I think he’s a Canuck; <a href=”http://www.gskinner.com/blog/archives/000065.html”>too cute not to be</a>), <a href=”http://www.gskinner.com/blog/”>Grant Skinner</a>, has <a href=”http://www.gskinner.com/blog/archives/000069.html”>posted</a> a neat way to utilize el activation object to quickly and easily scope your XML objects (LoadVars same way). Nestled in composition ‘esque classes, this is a great way to wire your XML document’s callback to your class so it can call a custom parsing method, etc. Better yet, if you place a var in front of the creation of the XML object, he’ll die when garbage collection comes along (supposedly).
However, I don’t agree this is a best practice. Course, nothing in Flash is really documented as such, most Flashers just generally agree and double check with Java peeps to ensure we can feel good about our decision to do so.
Doesn’t Grant Skinner look just like Clay Aikens ? Or is it just me ?
Hrm… indeed.
<a href=”http://www.gskinner.com/playpen/photo_200.jpg”>http://www.gskinner.com/playpen/photo_200.jpg</a>
<a href=”http://premium1.picturehost.co.uk/cp2.gif”>http://premium1.picturehost.co.uk/cp2.gif</a>
Umm… I’ll skip the discussion on my looks. I have to admit, I’m a little uncomfortable with Jesse calling me cute – I just hope it was Her Majesty. ;)
Anywho… here’s an update. This is the “right” way to do things, IMHO:
http://www.gskinner.com/blog/archives/000070.html
One day I’ll fix my comments, really, I will.
Clay Aikens? I resent that. I really look a lot more like Heman:
http://gskinner.com/playpen/gMan.jpg
That photo is totally undoctored.
Well, your proxy class is craploads better than mine, for sure. However, it follows the same pattern of loadMovie; do you get an error? What if it times out? Same reason I did that for a wrapper for loading images into movie clips; never thought about doing that for XML, though, fantastic idea!
At the minutae level, a wrapper period is correct, however, EventDispatcher (yours too), is so much better. I dig it!
Whoa, nice pic; when you run, are you at a 30 degree angle? I used to try to run like that…
This was my take on it a couple of months ago:
http://www.bit-101.com/blog/archives/000023.html
Lots of possible solutions. I still don’t know what the “right” way is.
Alternately, you might try making the XMLWrapper implement the new event-handling model so that you could attach a listener from the container object. That would get you where you want to go while still maintaining logical consistency with other classes you are using (assuming you’re working primarily with the new component set and don’t mind the slight extra processing overhead).
Alternately, you might try making the XMLWrapper implement the new event-handling model so that you could attach a listener from the container object. That would get you where you want to go while still maintaining logical consistency with other classes you are using (assuming you’re working primarily with the new component set and don’t mind the slight extra processing overhead).
Doh! – in the time it took me to get around to typing the suggestion he up and posted exactly that solution :(
I’d love an XML object that had these timeout/callback features, as well as Xpath functionality like this bit from Xfactor:
http://www.xfactorstudio.com/Actionscript/AS2/XPath
It amazes me that features like these aren’t built in by MM, and always end up being added by diligent users after the fact.
Hi ?
Grants original solution feels correct and analogous to Java anonymous classes.
public void aMethod ()
{
}
public void startThread ()
{
new Thread(new Runnable ()
{
public void run ()
{
aMethod();
}
}).start();
}
Here in this example aMethod is scoped to the parent class, the same class the Thread was created. Runnable is an interface instanciated as an anonymous class. I cant be certain but I seem to remember the compiler has a hand in making the run method have access to the parent class.
Ive used many similar solutions in AS2, eg.
interface IRequest
{
public function handleRequest (aRequest:Request)
}
class Foo
{
public function initHandlers ()
{
var _this:Foo = this;
// Create new instance of Irequest interface
var aHander:IRequest = new IRequest ();
// Define handleRequest method
aHandler.handleRequest = function ()
{
_this.doSomething();
}
this.setRequestHandler(?XXX.YYY?, aHandler);
}
}
Ive left some methods undefined however this seems to recreate the functionality of anonymous inner classes, using the activation object ?trick?. Of course we could do all this without the interface ? however the interface is essential really. Its our contract, but also provides comment like reminders of what the code is doing.
So, I guess, my point is that grants method is my best practice, or atleast in some situations, thoughts anyone?
Matt