Magazine Internet

[Flash] Phone Book en xml

Publié le 10 décembre 2007 par Avi Teboul

Voici comment réaliser un phone book avec un fichier xml...

Bonjour,

Voici comment réaliser un phonebook via xml.

1) Ouvrir flash.
2) Créez un document de 250X 250 et donnez comme couleur de fond : #333333.
3) Créez 4 calques : Texte, Champ, Boutons, AS.
4) Ecrivez sur la scene via l'objet texte statique : Nom, E-mail, Site web.
5) Dessinez 3 champs texte dynamique en dessous de chaque nom.
6) Donnez comme nom de variable : nom, mail et web
7) Tapez ce code sur la première frame du calque AS :

var contacts = new XML();
contacts.ignoreWhite = true;
var entry = 0;
var total = 0;
var current = 0;
contacts.load("contacts.xml");
contacts.onLoad = function(success) {
if (success) {
nom = this.firstChild.childNodes[_root.entry].attributes.nom;
mail = this.firstChild.childNodes[_root.entry].attributes.mail;
web = this.firstChild.childNodes[_root.entry].attributes.web;
_root.total = this.firstChild.childNodes.length;
_root.current = _root.entry + 1;
entryNum = _root.current+" of "+ _root.total;
}
};
stop();

8) Sur le calque Bouton dessinez un champs texte dynamique avec comme nom de variable : entryNum.
9) De chaque côté dessinez une flèche une vers la gauche et l'autre vers la droite.
10) Placez ce code sur le bouton de gauche :

on(press) {
if(_root.entry == 0) {
_root.entry = _root.total - 1;
} else {
_root.entry -= 1;
}
_root.contacts.load("contacts.xml");
}

Placez ce code sur le bouton de droite:

on(press) {
if(_root.entry + 1 == _root.total) {
_root.entry = 0;
} else {
_root.entry += 1;
}
_root.contacts.load("contacts.xml");
}

11) Voici le code du xml :

?xml version="1.0" encoding="ISO-8859-1"?>
contacts>
entry nom="User1" mail="[email protected]" web="http://www.user1.com"/>
entry nom="User2" mail="[email protected]" web="http://www.user2.com"/>
entry nom="User3" mail="[email protected]" web="http://www.user3.com"/>
entry nom="User4" mail="[email protected]" web="http://www.user4.com"/>
entry nom="User5" mail="[email protected]" web="http://www.user5.com"/>
/contacts>

Sauver ce fichier en UFT-8 et avec comme nom : contacts.xml

12) Ctrl+enter
13) Cliquez sur les flèches pour visualiser vos contacts.

Démo : ICI
Source : ICI

Bàv,
Burnside.


Retour à La Une de Logo Paperblog

A propos de l’auteur


Avi Teboul 600 partages Voir son profil
Voir son blog

l'auteur n'a pas encore renseigné son compte l'auteur n'a pas encore renseigné son compte