'this', .onLoad, its function literal (--and Delegate?)

  • jawasdi
  • Born
  • Born
  • jawasdi
  • Posts: 1

Post 3+ Months Ago

I am using a LoadVars() object inside a class. It's loading an external text file, and all is working in that regard. Here's part of the code that checks when the text file has been loaded; I named the loadvars object "load_info":
- - - - - - - - - - - - - - - - - - - - - - - - - - -
....load_info.onLoad = function(success:Boolean) {
........if (success) {
............trace("something"); //cool: this shows up.
........}
....}
- - - - - - - - - - - - - - - - - - - - - - - - - - -
But within the above function literal I need to be able to reference and set some of the properties of the class, and my first mistake was assuming that just using 'this' would do so, but it would be referencing the function object, and not the class object, as I soon found out.

I searched around and found that I probably need to use the Delegate utility in the newest version of mx 2004.

So I went over some Delegate examples, inc the one from the link:

http://www.kirupa.com/web/xml/XMLspecificIssues3.htm

and now my code in the class file looks is something like this:
- - - - - - - - - - - - - - - - - - - - - - - - - -
....import mx.utils.Delegate;
....class Something {
.... ...
....var load_info = new LoadVars();
....load_info.load("info.txt");
.... ...
....load_info.onLoad = Delegate.create(this, extract_info);
....function extract_info (success:Boolean):Void {
........trace("bla"); //this won't show in output,
........if (success) {
............trace("bla bla" + this); //and neither will this.
........{
....}
....}
- - - - - - - - - - - - - - - - - - - - - - - - - -
Now the onLoad itself does not work! (The trace messages above don't come up in Output.) As I mentioned, if I restructure the onload function in the format of the first code snippet above, then the onLoad at least works--but then i don't know how to fit in the Delegate.

So my main problem: need to be able to reference the class 'this' within the .onLoad function literal.

What am I doing wrong?

Thanks.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Try registering the onLoad event before initiating the load.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

Yes this event occurs because LoadVars() is an object itself... and the onLoad is called to that object so using 'this' in an onLoad targets the LoadVars() object.

This is really an interested problem and I wish I could help, but I still use Flash MX, and a lot has changed with object scopes since MX.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 7 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.