Attachsound aléatoire et HitTest. Problèmes.

flutiflupipo Messages postés 4 Date d'inscription jeudi 4 décembre 2008 Statut Membre Dernière intervention 20 janvier 2009 - 20 janv. 2009 à 02:41
flutiflupipo Messages postés 4 Date d'inscription jeudi 4 décembre 2008 Statut Membre Dernière intervention 20 janvier 2009 - 20 janv. 2009 à 12:23
Bonsoir!
Voilà mon problème, j'ai une séquence sur flash.

Dans cette séquence, j'ai une pluie d'objets. Et un plateau au sol permettant de faire rebondir les objets.
J'attache un son au rebond des objets contre le plateau.

Là tout va bien.

Mais j'aimerai avoir des sons aléatoires au contact du plateau. J'ai donc créé trois sons:
-rebond1.mp3
-rebond2.mp3
-rebond3.mp3

Et j'ai codé ceci:
vy=vy+.6;

this._x=this._x+vx;
this._y=this._y+vy;

if (this._y>800) {
this.removeMovieClip();
}

if (this._x<0) {
vx=-vx*.9;
this._x=0;
} else if (this._x>1280) {
vx=-vx*.9;
this._x=1280;
}



if (hitTest(_parent.mousecatch)) {
vy=-vy*.8;		
vx=(this._x-_parent.mousecatch._x)/15;

this._y=_parent.mousecatch._y-(this._height/2);

var my_sound:Sound = new Sound();
 function playRandomSound():Void{
  	 var numSon:Number = Math.round(Math.random()*3); 
 	  my_sound.attachSound("rebond"+numSon+".mp3");
 	  my_sound.start(0,1);
}
 


Mais ça ne marche pas.
Qu'ai-je loupé?
A voir également:

4 réponses

flutiflupipo Messages postés 4 Date d'inscription jeudi 4 décembre 2008 Statut Membre Dernière intervention 20 janvier 2009
20 janv. 2009 à 02:42
Oula je vais la refaire...
0
flutiflupipo Messages postés 4 Date d'inscription jeudi 4 décembre 2008 Statut Membre Dernière intervention 20 janvier 2009
20 janv. 2009 à 02:44
Bonsoir!
Voilà mon problème, j'ai une séquence sur flash.

Dans cette séquence, j'ai une pluie d'objets. Et un plateau au sol permettant de faire rebondir les objets.

J'attache un son au rebond des objets contre le plateau.

Là tout va bien.

Mais j'aimerai avoir des sons aléatoires au contact du plateau. J'ai donc créé trois sons:
-rebond1.mp3
-rebond2.mp3
-rebond3.mp3

Et j'ai codé ceci:

vy=vy+.6;

this._x=this._x+vx;
this._y=this._y+vy;

if (this._y>800) {
this.removeMovieClip();
}

if (this._x<0) {
vx=-vx*.9;
this._x=0;
} else if (this._x>1280) {
vx=-vx*.9;
this._x=1280;
}



if (hitTest(_parent.mousecatch)) {
vy=-vy*.8;
vx=(this._x-_parent.mousecatch._x)/15;

this._y=_parent.mousecatch._y-(this._height/2);

var my_sound:Sound = new Sound();
function playRandomSound():Void{
var numSon:Number = Math.round(Math.random()*3);
my_sound.attachSound("rebond"+numSon+".mp3");
my_sound.start(0,1);
}


Mais ça ne marche pas.
Qu'ai-je loupé?
0
cs_bali_balo Messages postés 1378 Date d'inscription samedi 9 octobre 2004 Statut Membre Dernière intervention 1 novembre 2010 1
20 janv. 2009 à 11:50
Il faudrait plutôt que tu aies un objet Sound() pour chaque son.


var son1 :Sound = new Sound( clip1 );

var son2 :Sound = new Sound( clip2 );

var son3 :Sound = new Sound( clip3 );
son1.attachSound( "son1.mp3" );
son2.attachSound( "son2.mp3" );
son3.attachSound( "son3.mp3" );

ensuite :
function playRandomSound():Void{

   _root["son"+random(3)+1].start();
}
ou bien :
var tabSons :Array = new Array( son1 , son2 , son3 );
function playRandomSound():Void{


   tabSons[radom(3)].start();

}

bali_balo....=]
0
flutiflupipo Messages postés 4 Date d'inscription jeudi 4 décembre 2008 Statut Membre Dernière intervention 20 janvier 2009
20 janv. 2009 à 12:23
C'est bon j'ai trouvé ce matin au travail.

function playRandomSound():Void{
var my_sound:Sound = new Sound();
var numSon:Number = Math.round(Math.random()*3);
my_sound.attachSound("rebond"+numSon+".mp3");
my_sound.start(0,1);
}


if (hitTest(_parent.mousecatch)) {
vy=-vy*.8;
vx=(this._x-_parent.mousecatch._x)/15;
this._y=_parent.mousecatch._y-(this._height/2);

playRandomSound();
}
0
Rejoignez-nous