A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: strange...

  1. #1
    Senior Member mbenney's Avatar
    Join Date
    Mar 2001
    Posts
    2,744

    strange...

    When debugging some xml code i came across this strange occurence... anyone explain why flash absolutley loves this code...
    code:

    doc = new XML();
    doc.ignoreWhite = true;
    doc.onLoad = fdoc;
    doc.load("links.xml");
    function fdoc() {
    trace(this)
    }



    but takes an instant dislike to this...

    code:

    doc = new XML();
    doc.ignoreWhite = true;
    doc.onLoad = fdoc;
    doc.load("links.xml");
    fdoc = function() {
    trace(this)
    }




    cofused, all thats different is the way that the functions are declared... both valid methods..
    [m]

  2. #2
    Member
    Join Date
    Jan 2003
    Location
    Australia, Adelaide (SA)
    Posts
    97
    Hi mbenney,

    When you declare something like
    code:

    fdoc = function(success)
    {
    trace(this)
    };


    You have declared an object constructor, eg:
    code:

    Person = function( name, age )
    {
    this._name = name;
    this._age = age;
    };
    Person.prototype.getDetails = function()
    {
    return "name: " + this._name + ", age: " + this._age;
    };

    var tim = new Person("Tim", "30");
    trace( tim.getDetails() );
    // output is "name: Tim, age: 30"


    As you see I defined an Object constructor and a function on that object.

    What you might have really wanted to do is something like this:
    code:

    doc = new XML();
    doc.ignoreWhite = true;
    doc.onLoad = function() {
    trace(this)
    }
    doc.load("links.xml");


    It's a confusion that should no longer be a problem in AS 2.0 (coming soon in Flash MX 2004).

    Hope this helps!
    Tim Walters
    Senior Developer
    XML Evangelist
    "XML isn't a language, it's a way of life!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center