5 Replies Latest reply on Oct 5, 2006 3:23 AM by Newsgroup_User

    XML loading and scope problem

    Level 7
      This is a multi-part message in MIME format.

      ------=_NextPart_000_0028_01C6E6E6.7CF11A00
      Content-Type: text/plain;
      charset="iso-8859-9"
      Content-Transfer-Encoding: quoted-printable

      hi,

      when XML file loaded, i dont understand onloaded function scope and i =
      cant use scope what I want.
      code below:=20

      class VoteChoicesGroup extends MovieClip
      {
      private var choicesXML : XML;
      function VoteChoicesGroup ()
      {
      MC =3D this;
      choicesXML =3D new XML ();
      choicesXML.onLoad =3D choicesLoaded;
      choicesXML.ignoreWhite =3D true;
      choicesXML.load ("XML/mainPageVoteChoices.xml");
      }
      =
      /////////////////////////////////////////////////////////////////////////=
      //////
      function choicesLoaded (success : Boolean) : Void
      {
      var choices : XMLNode =3D this ["childNodes"][0];
      if (success)
      {
      MC.item0.assignTitle (choices.childNodes [0].firstChild)
      trace ('MC: ' + MC)// this return as "undefined"

      }
      }
      }

      how can I reach top scope? I mean how can I see MC?

      Note: I thought using AddEventListener...but i cant use it on XML class =
      :)

      regards


      ------=_NextPart_000_0028_01C6E6E6.7CF11A00
      Content-Type: text/html;
      charset="iso-8859-9"
      Content-Transfer-Encoding: quoted-printable

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
      <HTML><HEAD>
      <META http-equiv=3DContent-Type content=3D"text/html; =
      charset=3Diso-8859-9">
      <META content=3D"MSHTML 6.00.5346.5" name=3DGENERATOR>
      <STYLE></STYLE>
      </HEAD>
      <BODY bgColor=3D#ffffff>
      <DIV><FONT face=3DArial size=3D2>hi,</FONT></DIV>
      <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
      <DIV><FONT face=3DArial size=3D2>when XML file loaded, i dont understand =
      onloaded=20
      function scope and i cant use scope what I want.</FONT></DIV>
      <DIV><FONT face=3DArial size=3D2>code below: </FONT></DIV>
      <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
      <DIV><FONT face=3DArial size=3D2><FONT face=3D"Courier New"><FONT =
      color=3D#800000>class=20
      VoteChoicesGroup extends MovieClip<BR></FONT>{<BR> private var =
      choicesXML :=20
      XML;<BR> function VoteChoicesGroup =
      ()<BR> {<BR>  <FONT=20
      color=3D#ff0000>MC =3D this;<BR></FONT>  choicesXML =3D new =
      XML=20
      ();<BR>  choicesXML.onLoad =3D=20
      choicesLoaded;<BR>  choicesXML.ignoreWhite =3D=20
      true;<BR>  choicesXML.load=20
      ("XML/mainPageVoteChoices.xml");<BR> }<BR> ////////////////////=
      ///////////////////////////////////////////////////////////<BR> <FON=
      T=20
      color=3D#008000>function choicesLoaded (success : Boolean) :=20
      Void</FONT><BR> {<BR>  var choices : XMLNode =3D this=20
      ["childNodes"][0];<BR>  if=20
      (success)<BR>  {<BR>   MC.item0.assignTitle=20
      (choices.childNodes [0].firstChild)<BR>   <FONT=20
      color=3D#ff0000>trace ('MC: ' + MC)// this return as=20
      "undefined"</FONT></FONT></FONT></DIV><FONT face=3DArial size=3D2><FONT=20
      face=3D"Courier New"><FONT color=3D#ff0000>
      <DIV><BR></FONT>  }<BR> }<BR>}</DIV>
      <DIV> </DIV>
      <DIV></FONT><FONT face=3DArial>how can I reach top scope? I mean how can =
      I see=20
      MC?</FONT></DIV>
      <DIV><FONT face=3DArial></FONT> </DIV>
      <DIV><FONT face=3DArial>Note: I thought using AddEventListener...but i =
      cant use it=20
      on XML class :)</FONT></DIV>
      <DIV><FONT face=3DArial></FONT> </DIV>
      <DIV><FONT face=3DArial>regards</DIV>
      <DIV><BR> </FONT></FONT></DIV></BODY></HTML>

      ------=_NextPart_000_0028_01C6E6E6.7CF11A00--

        • 1. Re: XML loading and scope problem (solved)
          Level 7
          This is a multi-part message in MIME format.

          ------=_NextPart_000_0010_01C6E6FC.3CF7D5E0
          Content-Type: text/plain;
          charset="iso-8859-9"
          Content-Transfer-Encoding: quoted-printable

          this.book_xml.onLoad =3D =
          Delegate.create(this,function(success:Boolean):Void {

          ///////77

          }

          "Burak Delice" <bdelice@delizade.com>, haber iletisinde =FEunlar=FD =
          yazd=FD:efta33$f8i$1@forums.macromedia.com...
          hi,

          when XML file loaded, i dont understand onloaded function scope and i =
          cant use scope what I want.
          code below:=20

          class VoteChoicesGroup extends MovieClip
          {
          private var choicesXML : XML;
          function VoteChoicesGroup ()
          {
          MC =3D this;
          choicesXML =3D new XML ();
          choicesXML.onLoad =3D choicesLoaded;
          choicesXML.ignoreWhite =3D true;
          choicesXML.load ("XML/mainPageVoteChoices.xml");
          }
          =
          /////////////////////////////////////////////////////////////////////////=
          //////
          function choicesLoaded (success : Boolean) : Void
          {
          var choices : XMLNode =3D this ["childNodes"][0];
          if (success)
          {
          MC.item0.assignTitle (choices.childNodes [0].firstChild)
          trace ('MC: ' + MC)// this return as "undefined"

          }
          }
          }

          how can I reach top scope? I mean how can I see MC?

          Note: I thought using AddEventListener...but i cant use it on XML =
          class :)

          regards


          ------=_NextPart_000_0010_01C6E6FC.3CF7D5E0
          Content-Type: text/html;
          charset="iso-8859-9"
          Content-Transfer-Encoding: quoted-printable

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <HTML><HEAD>
          <META http-equiv=3DContent-Type content=3D"text/html; =
          charset=3Diso-8859-9">
          <META content=3D"MSHTML 6.00.5346.5" name=3DGENERATOR>
          <STYLE></STYLE>
          </HEAD>
          <BODY bgColor=3D#ffffff>
          <DIV><FONT face=3DTheSansMonoCondensed-Plain size=3D1>
          <P align=3Dleft><FONT face=3D"Courier New" size=3D3>this.book_xml.onLoad =
          =3D=20
          Delegate.create(this,function(success:Boolean):Void {</FONT></P>
          <P align=3Dleft><FONT face=3D"Courier New" size=3D3>///////77</FONT></P>
          <P align=3Dleft><FONT face=3D"Courier New" =
          size=3D3>}</FONT></P></FONT></DIV>
          <BLOCKQUOTE dir=3Dltr=20
          style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
          BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
          <DIV>"Burak Delice" &lt;<A=20
          href=3D"mailto:bdelice@delizade.com">bdelice@delizade.com</A>&gt;, =
          haber=20
          iletisinde =FEunlar=FD =
          yazd=FD:efta33$f8i$1@forums.macromedia.com...</DIV>
          <DIV><FONT face=3DArial size=3D2>hi,</FONT></DIV>
          <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
          <DIV><FONT face=3DArial size=3D2>when XML file loaded, i dont =
          understand onloaded=20
          function scope and i cant use scope what I want.</FONT></DIV>
          <DIV><FONT face=3DArial size=3D2>code below: </FONT></DIV>
          <DIV><FONT face=3DArial size=3D2></FONT> </DIV>
          <DIV><FONT face=3DArial size=3D2><FONT face=3D"Courier New"><FONT=20
          color=3D#800000>class VoteChoicesGroup extends=20
          MovieClip<BR></FONT>{<BR> private var choicesXML : =
          XML;<BR> function=20
          VoteChoicesGroup ()<BR> {<BR>  <FONT color=3D#ff0000>MC =
          =3D=20
          this;<BR></FONT>  choicesXML =3D new XML=20
          ();<BR>  choicesXML.onLoad =3D=20
          choicesLoaded;<BR>  choicesXML.ignoreWhite =3D=20
          true;<BR>  choicesXML.load=20
          =
          ("XML/mainPageVoteChoices.xml");<BR> }<BR> ////////////////////=
          ///////////////////////////////////////////////////////////<BR> <FON=
          T=20
          color=3D#008000>function choicesLoaded (success : Boolean) :=20
          Void</FONT><BR> {<BR>  var choices : XMLNode =3D this=20
          ["childNodes"][0];<BR>  if=20
          (success)<BR>  {<BR>   MC.item0.assignTitle=20
          (choices.childNodes [0].firstChild)<BR>   <FONT=20
          color=3D#ff0000>trace ('MC: ' + MC)// this return as=20
          "undefined"</FONT></FONT></FONT></DIV><FONT face=3DArial =
          size=3D2><FONT=20
          face=3D"Courier New"><FONT color=3D#ff0000>
          <DIV><BR></FONT>  }<BR> }<BR>}</DIV>
          <DIV> </DIV>
          <DIV></FONT><FONT face=3DArial>how can I reach top scope? I mean how =
          can I see=20
          MC?</FONT></DIV>
          <DIV><FONT face=3DArial></FONT> </DIV>
          <DIV><FONT face=3DArial>Note: I thought using AddEventListener...but i =
          cant use=20
          it on XML class :)</FONT></DIV>
          <DIV><FONT face=3DArial></FONT> </DIV>
          <DIV><FONT face=3DArial>regards</DIV>
          <DIV><BR> </FONT></FONT></DIV></BLOCKQUOTE></BODY></HTML>

          ------=_NextPart_000_0010_01C6E6FC.3CF7D5E0--

          • 2. Re: XML loading and scope problem (solved)
            Level 7
            >MC = this;

            Good to store a reference like this, but I see you're calling it MC,
            probably for MovieClip - which it is not. You are storing a reference to the
            class itself. I usually call this classRef.

            Inside your choicesLoaded method MC is undefined because this method is
            called in the scope of the XML object. That's where using a Delegate solves
            your problem - which by your next email looks like you've already done. If
            you need help, just say...


            --
            Dave -
            Adobe Community Expert
            www.blurredistinction.com
            http://www.adobe.com/communities/experts/


            • 3. Re: XML loading and scope problem (solved)
              Level 7
              "You are storing a reference to the class itself. I usually call this
              classRef." you are absolutaly right. and i see that is really funny :) i
              mean using MC variable name :). actually when I since i have started to use
              OOP and ActionScript that word has became a habit of me. I put it
              automaticly untill you say that . thankyou very much



              "DMennenoh **AdobeCommunityExpert**" <dave@blurredistinction.com>, haber
              iletisinde þunlarý yazdý:eftlin$rtk$1@forums.macromedia.com...
              > >MC = this;
              >
              > Good to store a reference like this, but I see you're calling it MC,
              > probably for MovieClip - which it is not. You are storing a reference to
              > the class itself. I usually call this classRef.
              >
              > Inside your choicesLoaded method MC is undefined because this method is
              > called in the scope of the XML object. That's where using a Delegate
              > solves your problem - which by your next email looks like you've already
              > done. If you need help, just say...
              >
              >
              > --
              > Dave -
              > Adobe Community Expert
              > www.blurredistinction.com
              > http://www.adobe.com/communities/experts/
              >


              • 4. Re: XML loading and scope problem (solved)
                Level 7
                btw, when I understood using "this" is a wrong way, i decided to assign it
                to a variable. But I could not understand why I cant use "this" instead of
                assigning it to a variable? could you tell me why if it is possible

                regards,
                Burak


                "DMennenoh **AdobeCommunityExpert**" <dave@blurredistinction.com>, haber
                iletisinde þunlarý yazdý:eftlin$rtk$1@forums.macromedia.com...
                > >MC = this;
                >
                > Good to store a reference like this, but I see you're calling it MC,
                > probably for MovieClip - which it is not. You are storing a reference to
                > the class itself. I usually call this classRef.
                >
                > Inside your choicesLoaded method MC is undefined because this method is
                > called in the scope of the XML object. That's where using a Delegate
                > solves your problem - which by your next email looks like you've already
                > done. If you need help, just say...
                >
                >
                > --
                > Dave -
                > Adobe Community Expert
                > www.blurredistinction.com
                > http://www.adobe.com/communities/experts/
                >


                • 5. Re: XML loading and scope problem (solved)
                  Level 7
                  >>btw, when I understood using "this" is a wrong way, i decided to assign it
                  to a variable. But I could not understand why I cant use "this" instead of
                  assigning it to a variable? could you tell me why if it is possible


                  Sorry, I don't quite understand your question. In your orignal code,
                  assigning 'this' to MC didn't help as it was still undefined inside
                  choicesLoaded. Calling it with a delegate allows you to call it in whatever
                  scope you like. In your example, you wouldn't even need to use MC after
                  using the delegate, because 'this' would then be in the scope you wanted -
                  the class, and not the XML object.

                  --
                  Dave -
                  Adobe Community Expert
                  www.blurredistinction.com
                  http://www.adobe.com/communities/experts/