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
|
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import caurina.transitions.*;
//Rayon de rotation autour de l'axe y
var Rx:Number=200;
var Ry:Number=60;
//Nombre d'icones
var N:Number=3;
//angle de rotation des clips autour de l'axe z
var angle:Number=0;
//Attachement des icones
var Reference:Class;
for (var i:Number=0; i<N; i++) {
// extraction des références de classe
Reference=Class(getDefinitionByName("MonClip"+i));
// ajout à la liste d'affichage
this.addChild( DisplayObject ( new Reference() ) );
//Nom du clip
this.getChildAt(i).name='ID'+i;
//position initial du ieme clip en y
this.getChildAt(i).y=stage.stageHeight/2;
//Position initial du ieme clip en x
this.getChildAt(i).x=Rx*Math.cos(2*Math.PI*i/N)+stage.stageWidth/2;
//taille initiale du ieme clip
this.getChildAt(i).scaleX=0.6/2*(Math.sin(2*Math.PI*i/N)+ 1)+0.4;
this.getChildAt(i).scaleY=this.getChildAt(i).scaleX;
//ecouteur enter_frame
stage.addEventListener( Event.ENTER_FRAME, Main );
function Main( pEvt:Event ):void {
//variable temporaire pour la profondeur
var z:Number;
//si l'angle a fait un tour alors remise a zero de l'angle
if (angle>2*Math.PI) {
angle=0;
} else {
for (i=0; i<N; i++) {
//rotation du i_eme clip sur x
this.getChildByName('ID'+i).x=Rx*Math.cos(angle+2*Math.PI*i/N)+stage.stageWidth/2;
this.getChildByName('ID'+i).y=Ry*Math.sin(angle+2*Math.PI*i/N)+stage.stageHeight/2;
//mise a jour de la taille du clip (60%->premier plan, 40%->arriere plan)
this.getChildByName('ID'+i).scaleX=0.6/2*(Math.sin(angle+2*Math.PI*i/N)+ 1)+0.4;
this.getChildByName('ID'+i).scaleY=getChildByName('ID'+i).scaleX;
//mise a jour de z
z=(N-1)*(Math.sin(angle+2*Math.PI*i/N)+1)/2;
this.setChildIndex(this.getChildByName('ID'+i), int(z));
}
//rotation commandée par la souris
//conditions sur x
if (stage.mouseX<(stage.stageWidth/2+(Rx+10000)) && stage.mouseX>(stage.stageWidth/2-(Rx+10000))) {
//conditions sur y
if (stage.mouseY<stage.stageHeight&&stage.mouseY>0) {
//0.7 correspond a la vitesse
angle=angle+(stage.mouseX-stage.stageWidth/2)/stage.stageWidth*0.4;
}
}
}
}
//ajout d'un ecouteur sur le ieme clip
this.getChildAt(i).addEventListener(MouseEvent.CLICK, onclick);
function onclick( pEvt:MouseEvent ):void {
for (var i:Number=0; i<stage.numChildren; i++) {
stage.getChildAt(i)!=pEvt.target;
stage.removeEventListener (Event.ENTER_FRAME, Main);
Tweener.addTween (clip, {x:700, y:30, time:1, transition:"Elastic"});
}
}
}
var clip=new myClip();// ça créé une nouvelle occurence de ton clip
addChild(clip);// ça l'ajoute à la liste d'affichage du stage
clip.x=400;
clip.y=200; |
Partager