Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > Flash/Flex > Flash > AS1/AS2
AS1/AS2 Questions relatives à la programmation ActionScript 1 et 2 (Cours AS2)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 04/06/2007, 16h16   #1
Membre du Club
 
Inscription : mai 2007
Messages : 127
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 127
Points : 43
Points : 43
Par défaut Soucis de scopage en flash et as

Bonjour à vous tous !
Je fait appel à vous, car là, je seche totalement !! :p
Je m'explique, j'ai une classe as MyTree, qui gere un composant Tree.
Jusque là tout va bien.
Comme tout tree qui se respecte, je fait appel à un composant XML pour charger mes données. C'est la que les problemes arrivent.
J'ai mon objet XML qui va bien dans la fonction onLoad, mais dans la fonction onLoad, j'ai le this qui contient l'arbre XML, mais ma variable myTree, qui contient le movieclip Tree, est undefined (probleme de scopage donc).
A ce moment là, je me dit "pas grave, fait appel à la fonction mx.utils.Delegate"), ce que je fait ! Mais maintenant, dans mon this, j'ai plus l'arbre xml, j'ai mon objet MyTree... je fait comment pour avoir l'arbre maintenant ??? :p

Voici mon code si ca peux aider :

Code :
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
 
import mx.controls.Tree;
 
class MyTree extends Tree {
	private var myTree:Tree;
	private var ScrollBarLength:Number = 20;
	private var CurrentTree:Tree;
	private var treeListener:Object;
	private var myXML:XML;
 
	function MyTree (TreeElement:Tree, HorizontalScroll:String, HorizontalScrollLength:Number) {
		if (HorizontalScroll == null) HorizontalScroll = "off";
		if (HorizontalScrollLength == null) HorizontalScrollLength = 0;
 
		myTree = TreeElement;
		CurrentTree = TreeElement;
		myTree.hScrollPolicy = HorizontalScroll;
		myTree.maxHPosition = HorizontalScrollLength;
		treeListener = new Object();
		myXML = new XML ();
		myXML.onLoad = mx.utils.Delegate.create (this, onXMLLoad);
		treeListener.nodeOpen = mx.utils.Delegate.create (this, onNodeOpen);
		treeListener.change = mx.utils.Delegate.create (this, onChange);
		myTree.addEventListener ("nodeOpen", treeListener);
		myTree.addEventListener ("change", treeListener);
	}
 
	function onNodeOpen (evt:Object) {
		var menuTree = evt.target;
		var node = evt.node;
		CurrentTree = node;
		//trace (IndexServerAdress+"?path="+escape (node.attributes.data+node.attributes.label)+"/");
		//dXMLFile.load(IndexServerAdress+"?path="+escape (node.attributes.data+node.attributes.label)+"/");
		//menuTree.selectedNode = null;
	}
 
	function onChange () {
		trace ("On Change");
	}
 
	function onXMLLoad (DataProvider:XML) {
		trace (this);
		if (DataProvider.hasChildNodes() == true) {
			CurrentTree.removeAll();
			for (var i:Number = 0; i < DataProvider.childNodes[0].childNodes.length; i++) {
				var sCurrentNodeName:String = DataProvider.childNodes[0].childNodes[i].nodeName;
				var sCurrentLabel:String = DataProvider.childNodes[0].childNodes[i].attributes.label;
 
				if (sCurrentNodeName == "folder") {
					var sCurrentPath:String = DataProvider.childNodes[0].childNodes[i].attributes.path;
					//var test:Object = [{path:sCurrentPath}, {test:this.childNodes[0].childNodes[i].attributes.test}];
					var aNewNode:Object = CurrentTree.addTreeNode (sCurrentLabel, sCurrentPath);
					myTree.setIsBranch (aNewNode, true);
				}
				else if (DataProvider.childNodes[0].nodeName == "error") {
					trace ("ERROR : "+this);
				}
				else {
					var sCurrentSrc:String = DataProvider.childNodes[0].childNodes[i].attributes.src;
					CurrentTree.addTreeNode (sCurrentLabel, sCurrentSrc);
				}
			}
			//trace (aMusicTree.redraw());
			//aMusicTree.invalidate ();
		}
	}
 
	function loadXML (XMLPath:String) {
		myXML.load (XMLPath);
	}
}
et dans le fichier fla je fait :

var monTree:MyTree = new MyTree (ElementTree, "on", 200);
monTree.loadXML ("http://127.0.0.1/actual/folder/index.php");

Soi je récupere this en tant qu'arbre xml, soit en tant qu'occurence de l'objet this
J'aimerai les deux !! :p

Merci de votre aide !
Merci beaucoup ...
codefalse est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/06/2007, 19h33   #2
Inactif
 
Avatar de CR_Gio
 
Inscription : septembre 2005
Messages : 1 196
Détails du profil
Informations forums :
Inscription : septembre 2005
Messages : 1 196
Points : 1 201
Points : 1 201
bonjour,

Voici un petit exemple :
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Toto
{
  private var my_xml:XML;
  static var my_num:Number=0;
  ...
  function Toto()
  {
    var thisClass:Toto=this;
    this.my_xml.onLoad=function(succes:Boolean)
    {
      thisClass.my_num++;
      thisClass.TotoItem();
    };
  }
  private function TotoItem()
  {
    trace("Il y a "+this.my_num+" occurence Toto chargé");
  }
}
CR_Gio est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/06/2007, 19h42   #3
Membre du Club
 
Inscription : mai 2007
Messages : 127
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 127
Points : 43
Points : 43
Dois-je croire ce que tu dit à cause de ta signature ?

Merci beaucoup de ton reply, je m'y attele tout de suite, je te dit ce qu'il en est !
Merci beaucoup !
codefalse est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 04/06/2007, 19h49   #4
Membre du Club
 
Inscription : mai 2007
Messages : 127
Détails du profil
Informations forums :
Inscription : mai 2007
Messages : 127
Points : 43
Points : 43
Rooo ca marche !!!
Merci merci merci merci milles fois !!!!
codefalse est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 07h42.


 
 
 
 
Partenaires

Hébergement Web