Bonsoir !

Je suis étudiant, et je n'ai que de très faibles notions d'acionscript (ma spécialité étant plus le graphisme). Je suis en train de bosser mon nouveau portfolio, mais me voilà bloqué dès le début: j'ai une fonction, qui au chargement de l'animation charge une image de fond aléatoire d'après une liste XML. J'aimerais que mon bouton (btn_ap) ré-exécute les 2 fonctions qui chargent l'arrière-plan aléatoire.

J'ai pu trouver une solution, visible ici, mais c'est avec 2 images sur la ligne temporelle, et comme je vais devoir ensuite utiliser celle-ci pour faire les différentes sections de mon portfolio.

La solution serait de combiner les 2 fonctions distinctes qui font ce chargement d'arrière plan aléatoire afin de la faire exécuter lors du clic sur le bouton... Mais je n'ai aucune idée de comment procéder.

voici le code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
/* 
Flashandmath.com tutorial by Doug Ensley. See "Loading Random Images from an XML List in Flash CS3" in the Basic section for documentation.
 
Last modified on August 13, 2008.
*/
 
 
 
var ap_largeur:Number = 900;
var ap_hauteur:Number = 550;
 
var listLoader:URLLoader = new URLLoader( new URLRequest("ap.xml") );
var picLoader:Loader = new Loader();
 
listLoader.addEventListener(Event.COMPLETE, gotList);
 
function gotList(evt:Event):void {
  	var xmlData:XML = XML(listLoader.data);
  	var numImages:Number = xmlData.pix.length();
 
  	var stImage:String = xmlData.pix[Math.floor(numImages*Math.random())].toString();
 
	picLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, gotPic);
	picLoader.load( new URLRequest(stImage) );
 
	listLoader.removeEventListener(Event.COMPLETE, gotList);
}
 
function gotPic(evt:Event):void {
	var thisBmp:Bitmap = Bitmap(evt.target.content);
	thisBmp.x = 0;
	thisBmp.y = 0;
	var thisWidth:Number = thisBmp.width;
	var thisHeight:Number = thisBmp.height;
 
	thisBmp.scaleX = ap_largeur/thisWidth;
	thisBmp.scaleY = ap_hauteur/thisHeight;
	addChild(thisBmp);
	setChildIndex(thisBmp,numChildren-2);
	picLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,gotPic);
}
 
stop()
 
btn_ap.addEventListener(MouseEvent.MOUSE_DOWN,random_ap);
 
function random_ap(evt:MouseEvent) {
	gotoAndPlay(1)
}
 
setChildIndex(btn_ap,numChildren-1);