losing this pointer in onLoad callback

Ask a Question related to Macromedia Flash, Design and Development.

  1. #1

    Default losing this pointer in onLoad callback

    Hi There,

    I am having trouble with object pointers when i am loading an external XML
    file. I create a new XML object within a movieclip.
    On the onLoad of the XML object i call a function (method) cb_onLoadXML of
    the movieclip. When the callback function is called,
    i seem to have lost the this pointer of the movieclip.
    I am using Flash 5 for this particular project (customer does not have the
    budget for updating the application :-))

    Does anyone have any idea why this is and how i can prevent it?

    To make things easier to understand i have included some code:

    // movieclip mcSendResults
    function doSend() {
    this.anyvar = 5;

    this.objXML = new XML();
    this.objXML = ignoreWhite = true;
    this.objXML.onLoad = cb_onLoadXML;
    this.objXML.load(path);
    }

    function cb_onLoadXML(succes) {
    nodeRoot = this.objXML;

    if (this.anyvar < 10) {
    do xml parsing
    }
    }

    My problem is that the nodeRoot is empty. I think because the method is
    called in a callback structure of the XL object.
    The movieclip this pointer is lost.

    thanx for any hints or tips.



    Woutert Guest

  2. Similar Questions and Discussions

    1. Need help: Problems with XML.onLoad()
      :confused; Need some help with a problem i have in variable scoping. I was twidling around with one of Macromedia's sample files --- the...
    2. onload validation
      i want an error message THAT LOOKS LIKE THE FLASH FORM ERROR MESSAGES to appear as soon as a form loads. I wrote this but it doesnt work <cfform...
    3. Mouse pointer flickers between hand and pointer
      I have created a menu. On the menu options for some reason my mouse pointer flickers between a hand and pointer. Did anyone have this problem and...
    4. What is a callback?
      Hello everyone, I've seen the word "callback" used in a few Changelogs for a few modules saying that a few callbacks were fixed in the module. I...
    5. onload/onopen
      once i updated to office 2000 sp3 and windows 2000 sp4, access will no longer fire up the onload and onopen.
  3. #2

    Default Re: losing this pointer in onLoad callback

    The callbacks are called without the context you have in mind. I normally do
    this by stashing a handle in the XML object. This works in MX, don't know
    about 5.

    x = new XML();
    x.context = callingThis; // or whatever

    x.onLoad = function(status) {
    this.context.onLoad(status); // relay to instigating object
    }

    callingThis.onLoad = function(status) { ... what you want to do

    x.load(someUrl); ....

    It would have been nice if they had bothered to mention the callback
    context, but they like people to guess .....

    Ciaran

    "Woutert" <no.spam@12move.nl> wrote in message
    news:3f968d33$0$58709$e4fe514c@news.xs4all.nl...
    > Hi There,
    >
    > I am having trouble with object pointers when i am loading an external XML
    > file. I create a new XML object within a movieclip.
    > On the onLoad of the XML object i call a function (method) cb_onLoadXML of
    > the movieclip. When the callback function is called,
    > i seem to have lost the this pointer of the movieclip.
    > I am using Flash 5 for this particular project (customer does not have the
    > budget for updating the application :-))
    >
    > Does anyone have any idea why this is and how i can prevent it?
    >
    > To make things easier to understand i have included some code:
    >
    > // movieclip mcSendResults
    > function doSend() {
    > this.anyvar = 5;
    >
    > this.objXML = new XML();
    > this.objXML = ignoreWhite = true;
    > this.objXML.onLoad = cb_onLoadXML;
    > this.objXML.load(path);
    > }
    >
    > function cb_onLoadXML(succes) {
    > nodeRoot = this.objXML;
    >
    > if (this.anyvar < 10) {
    > do xml parsing
    > }
    > }
    >
    > My problem is that the nodeRoot is empty. I think because the method is
    > called in a callback structure of the XL object.
    > The movieclip this pointer is lost.
    >
    > thanx for any hints or tips.
    >
    >
    >

    Ciaran Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139