PDA

View Full Version : Function calling problem...


etiennelj
07-28-2008, 03:44 AM
I've been spending the last 3 hours on this stupid problem so I need your help please!

The thing is that I am not able to call my "soundManager" function on the onKeyDown event with the "usrinputManager" function...

The trace "left"/"right" works, but not the "soundManager" function calling.

What's wrong?

ActionScript Code:


class main {
private var pitch:Number = 5;
public function main() {
usrinputManager();
soundManager();
}
public function soundManager(pitchIncrement) {
trace("soundManager called");
var soundPath:String = "assets/sounds/";
var ySound:Sound = new Sound();
pitch == pitch+pitchIncrement;
ySound.loadSound(soundPath+pitch+".mp3",false);
ySound.onLoad = function(success:Boolean) {
ySound.start();
};
}
public function usrinputManager() {
trace("usrinputManager called");
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
//trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
switch (Key.getCode()) {
case 37 ://left key
soundManager(-1);
trace("left");
break;
case 39 ://right key
soundManager(1);
trace("right");
break;
}
};
Key.addListener(keyListener);
}
}

DiamondDog
07-28-2008, 08:28 AM
Not saying this will solve it completely, but shouldn't this:pitch == pitch+pitchIncrement; be this:pitch = pitch+pitchIncrement;?

Or you could do this:pitch += pitchIncrement;

CW.Allen-Poole
07-28-2008, 11:07 AM
Did you name your linkages 1.mp3, 2.mp3, etc?

etiennelj
07-28-2008, 01:04 PM
DiamondDog:

Yeah, thanks, I corrected this, but it's not the core of the problem...


CWAllen-Poole:

Since I didn't used "attachSound" but "loadSound", I don't need to use linkage because the files are not in Flash's library but in a folder on the disk. Don't worry, the only time when this fonction is called, through the constructor function, everything works well...

The problem is with triggering this function with the "onKeyDown" event... Because the "trace" works, but not the function calling...