Toon posts:

[Flash/AS 2.0] Voorkomen gebruik sleutelwoord '_root'

Pagina: 1
Acties:

Verwijderd

Topicstarter
Use this, this._parent, or _parent keywords rather than _root, depending on where your ActionScript is located.
Wanneer moet je '_parent' en wanneer moet je 'this._parent' gebruiken? Je zou toch standaard altijd met 'this._parent' moeten kunnen volstaan?

  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

Dat is natuurlijk afhankelijk van de scope.


Flash ActionScript:
1
2
3
4
5
6
7
function something () {}
something.prototype.somemethod = function () { 
   trace ( this._parent );   // oops
}

obj = new something ();
obj.somemethod ();

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Verwijderd

Topicstarter
drm schreef op vrijdag 23 september 2005 @ 16:40:
Dat is natuurlijk afhankelijk van de scope.


Flash ActionScript:
1
2
3
4
5
6
7
function something () {}
something.prototype.somemethod = function () { 
   trace ( this._parent );   // oops
}

obj = new something ();
obj.somemethod ();
Wanneer gebruik je bijvoorbeeld '_parent' zonder 'this'?

  • XangadiX
  • Registratie: Oktober 2000
  • Laatst online: 25-03 10:55

XangadiX

trepanatie is zóó kinderachtig

Verwijderd schreef op vrijdag 23 september 2005 @ 16:47:
[...]


Wanneer gebruik je bijvoorbeeld '_parent' zonder 'this'?
nou, als het met this._parent niet werkt en met _parent wel dan zou ik _parent gebruiken :>

Stoer; Marduq


Verwijderd

Zowel "_parent" als "this._parent" zijn toegestaan en doen precies hetzelfde. Leer jezelf echter aan om altijd "this" te gebruiken. Onderstaand voorbeeld geeft aan waar het mis zou kunnen gaan wanneer je this niet gebruikt:

PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class myClass 
{
    private var name:String;

    function myClass ()
    {
        super ();
    }

    
    private function setName ( name:String ):Void
    {
        this.name = name;
    }
}

Verwijderd

drm schreef op vrijdag 23 september 2005 @ 16:40:
Dat is natuurlijk afhankelijk van de scope.


Flash ActionScript:
1
2
3
4
5
6
7
function something () {}
something.prototype.somemethod = function () { 
   trace ( this._parent );   // oops
}

obj = new something ();
obj.somemethod ();
Zie ik prototype staan? :r

  • microchip
  • Registratie: Maart 2004
  • Laatst online: 29-05-2021
offtopic:
Prototype is soms HEEL handig om bestaande classen uit te bereiden. Om bijvoorbeeld alle MovieClip instances een bepaalde methode te geven.

[ Voor 8% gewijzigd door microchip op 24-09-2005 18:16 ]


  • drm
  • Registratie: Februari 2001
  • Laatst online: 09-06-2025

drm

f0pc0dert

FlashAddict:
Zie ik prototype staan? :r
That is, mind you, totally besides the point.

Music is the pleasure the human mind experiences from counting without being aware that it is counting
~ Gottfried Leibniz


Verwijderd

microchip schreef op zaterdag 24 september 2005 @ 18:16:
offtopic:
Prototype is soms HEEL handig om bestaande classen uit te bereiden. Om bijvoorbeeld alle MovieClip instances een bepaalde methode te geven.
Dat kan ook met classes:)
PHP:
1
2
3
class myClass extends MovieClip
{
}
drm schreef op zaterdag 24 september 2005 @ 23:34:
[...]
That is, mind you, totally besides the point.
offtopic:
Een reactie naar meer dan 2 jaar afwezigheid en meteen voelt het weer lekker als vanouds hier in /13!

[ Voor 31% gewijzigd door Verwijderd op 25-09-2005 02:51 ]


Verwijderd

Je "moet" gebruik maken this._parent in ActionScript 1.0 en in ActionScript 2.0 heb je de keuze om het wel of niet te gebruiken (scoping issue).
Pagina: 1