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
|
package {
import flash.display.*;
import flash.events.*;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
public class Puce extends Sprite
{
private var positionX:Number;
private var positionY:Number;
private var nomZac:String;
private var puce:clp_puce;
private var box:clp_box;
public function Puce(pX:Number, pY:Number, Zac:String)
{
positionX = pX;
positionY = pY;
nomZac = Zac;
// création de l'objet de type clp_puce
puce = new clp_puce();
addChild(puce);
puce.x = positionX;
puce.y = positionY;
puce.addEventListener(MouseEvent.MOUSE_OVER,auSurvol);
puce.addEventListener(MouseEvent.MOUSE_OUT,alExterieur);
}
public function getPositionX():Number
{
return positionX;
}
public function getPositionY():Number
{
return positionY;
}
public function getNomZac():String
{
return nomZac;
}
public function getContenu(e:MovieClip):String {
return nomZac;
}
private function auSurvol(event:MouseEvent):void {
box = new clp_box();
box.x = stage.stageWidth;
box.y = 0;
var tweenX, tweenY:Tween;
addChild(box);
tweenX = new Tween(box, "x", Bounce.easeOut,box.x + 100, box.x,15,false);
tweenX = new Tween(box, "y", Bounce.easeOut,box.y + 50, box.y,15,false);
var chargeurXML:URLLoader = new URLLoader();
//chargeurXML.dataFormat = URLLoaderDataFormat.TEXT;
chargeurXML.addEventListener(Event.COMPLETE, gestionXML);
chargeurXML.load(new URLRequest("zac.xml"));
trace("chargement XML..");
}
private function alExterieur(event:MouseEvent):void {
removeChild(box);
}
function calculerLongueur(liste:XMLList):uint {
var compteur:uint = 0;
for each (var elt:XML in liste) {
compteur++;
}
return compteur;
}
public function gestionXML(e:Event):void {
try {
var nom, description:String;
var nbZac:uint;
var elt:XML;
// Créer un objet XML et un objet XMLList
var donneesLues:XML = new XML(e.target.data);
var listeZac:XMLList = new XMLList();
// Rechercher les attributes de la balise Zac
listeZac = donneesLues.elements();
nbZac = calculerLongueur(listeZac);
// Pour toutes les zac définies dans l'arbre
for (var i:int=0; i < nbZac; i++) {
if(donneesLues.zac[i].@nom == this.getNomZac())
{
nom = donneesLues.zac[i].@nom;
description = donneesLues.zac[i].@description;
}
}
box.txt_contenu_box.text = nom;
box.txt_desc_box.text = description;
} catch (e:TypeError) {
trace("Imposible de charger le XML");
trace(e.message);
}
}
}
} |
Partager