Referencing Objects using 'This'

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

  1. #1

    Default Referencing Objects using 'This'

    Here is my problem i have a class called test and in that class I have a
    function called loadxml. So it looks something like:

    class test
    {
    var username:String = 'vince';

    function loadxml()
    { var moxml:XML = new XML();
    moxml.onLoad = handlereturn;
    moxml.load('uiconf.xml');
    }

    function handlereturn()
    {
    trace(this.toString());
    trace(username); //this will not work because of lose of scope
    }

    }

    Ok how can I refence back to the object from the handlereturn. The
    handlereturn has no idea which instantiated object sent the load call. In
    Flash MX I was able to do:
    moxml.parent = this;
    I would do this prior to load xml. Then the handlereturn should be able to
    call this.parent and have reference back to the object. How do I do this in
    2004. I tried extending the XML calls and added on member variable called
    moparent. The variable moxml became an instance of this new class (let's say
    sXML). However the handleresults cannot access the parent. I get a compile
    error saying no property.

    Anyone know of a quick and efficent way of doing this. I guess what I am
    trying to do is regain scope.

    Vince

    0Visual Guest

  2. Similar Questions and Discussions

    1. Newbie Question? Aligning Objects to other Objects?
      Hi, I think this a newbie question and I will try to explain it as best as possible! I have a hollow circle (no fill, or stroke) and x amount of...
    2. Referencing Movie Clips / Objects
      I have a form composed of Movie Clips of type Input Text which all have a unique instance name. I want to be able to call each of those input...
    3. Storing Objects/Arrays in Stored Objects
      Hello All, I recently came across a very frustrating issue when trying to create and store arrays within objects in a Shared object. It took me...
    4. Referencing Clicked Objects
      Perhaps a silly question since I am new to actionscript ... but: Is there a way to refererence a clicked object (=button) within an on (release)...
    5. referencing problem, or so i think
      // Hi I can't seem to pass the right instance to the function move Make_bg() //initiate...
  3. #2

    Default Re: Referencing Objects using 'This'

    ok, I ran into this and this is going to sound really weird, but it works.

    class test
    {
    var username:String = 'vince';

    function loadxml()
    { var moxml:XML = new XML();
    moxml.onLoad = handlereturn;
    moxml.__proto__._parent = this;
    moxml.load('uiconf.xml');
    }

    function handlereturn()
    {
    trace(this.toString());
    var myParent:Object = this._parent;
    trace(myParent.username); //this will not work because of lose of
    scope
    }

    }



    "0Visual" <webforumsuser@macromedia.com> wrote in message
    news:c287s7$j7s$1@forums.macromedia.com...
    > Here is my problem i have a class called test and in that class I have a
    > function called loadxml. So it looks something like:
    >
    > class test
    > {
    > var username:String = 'vince';
    >
    > function loadxml()
    > { var moxml:XML = new XML();
    > moxml.onLoad = handlereturn;
    > moxml.load('uiconf.xml');
    > }
    >
    > function handlereturn()
    > {
    > trace(this.toString());
    > trace(username); //this will not work because of lose of scope
    > }
    >
    > }
    >
    > Ok how can I refence back to the object from the handlereturn. The
    > handlereturn has no idea which instantiated object sent the load call. In
    > Flash MX I was able to do:
    > moxml.parent = this;
    > I would do this prior to load xml. Then the handlereturn should be able
    to
    > call this.parent and have reference back to the object. How do I do this
    in
    > 2004. I tried extending the XML calls and added on member variable called
    > moparent. The variable moxml became an instance of this new class (let's
    say
    > sXML). However the handleresults cannot access the parent. I get a
    compile
    > error saying no property.
    >
    > Anyone know of a quick and efficent way of doing this. I guess what I am
    > trying to do is regain scope.
    >
    > Vince
    >

    James Fee Guest

  4. #3

    Default Re: Referencing Objects using 'This'

    I get a compile error telling me the _proto_ cannot me found. Is your example
    based on ActionScript 1.0? In Actionscript 2.0 you can't do this. That's why
    I tried to extend the XML class to included this new variable.



    0Visual 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