Hi guys,
I’m trying to create a guitar, and I’ve sliced 6 strings in photoshop, and overlayed them onto the main image of the guitar. I’ve made each string a movie clip, and put some AS3 in to try to detect when a guitar pick (also a movie clip) is dragged over each string… Eventually in order to get it to play that corresponding note.
At present, I’ve got the following code:
guitarPick.addEventListener(MouseEvent.MOUSE_DOWN, drag);
guitarPick.addEventListener(MouseEvent.MOUSE_UP, drop);
E_string.addEventListener(Event.ENTER_FRAME, checkHit_E);
A_string.addEventListener(Event.ENTER_FRAME, checkHit_A);
D_string.addEventListener(Event.ENTER_FRAME, checkHit_D);
G_string.addEventListener(Event.ENTER_FRAME, checkHit_G);
B_string.addEventListener(Event.ENTER_FRAME, checkHit_B);
e_high.addEventListener(Event.ENTER_FRAME, checkHit_eHigh);
function drag(event:MouseEvent):void {
guitarPick.startDrag();
demoArrow.visible = false;
}
function drop(event:MouseEvent):void {
guitarPick.stopDrag();
demoArrow.visible = true;
guitarPick.x = 313.9;
guitarPick.y = 278.1;
}
function checkHit_E(event):void {
if(guitarPick.hitTestObject(E_string)){
hit_txt.text = "Low E";
} else {
hit_txt.text = "No string";
}
}
function checkHit_A(event):void {
if(guitarPick.hitTestObject(A_string)){
hit_txt.text = "A String";
} else {
hit_txt.text = "No string";
}
}
function checkHit_D(event):void {
if(guitarPick.hitTestObject(D_string)){
hit_txt.text = "D String";
} else {
hit_txt.text = "No string";
}
}
function checkHit_G(event):void {
if(guitarPick.hitTestObject(G_string)){
hit_txt.text = "G String";
} else {
hit_txt.text = "No string";
}
}
function checkHit_B(event):void {
if(guitarPick.hitTestObject(B_string)){
hit_txt.text = "B String";
} else {
hit_txt.text = "No string";
}
}
function checkHit_eHigh(event):void {
if(guitarPick.hitTestObject(e_high)){
hit_txt.text = "High E";
} else {
hit_txt.text = "No string";
}
}
But for some reason, only the high e works (last bit of code). I’m not sure why this is, because when no other string works, even with the same code (just names of movie clips changed).
I ran some trace statements, and I don’t think I’m using the right event listener, as it prints stuff out when the flash loads, but I’m not sure when I should be checking whether the pick has hit the string.
I tried mouse_over, but because the mouse is already down (to drag the pick), it doesn’t realise that you’ve gone over the string I don’t think.
Any help is greatly appreciated! This is my first day using AS3 and Flash CS4, and I’ve spent three hours this morning scouring the net for tutorials on how to do what I have so far
Thanks again,
Luke.