Skip to main content
Participant
April 28, 2014
Answered

crosshair can shoot but sound effect doesn't work

  • April 28, 2014
  • 1 reply
  • 338 views

hi all i'm new to adobe flash cs6.  I want to create some shooting games here, but i've got some problem

i Have my action script like this :

import flash.events.Event;

import flash.events.MouseEvent;

addEventListener(Event.ENTER_FRAME,aaa);

function aaa(e:Event)

{

    crosshair.x = mouseX;

    crosshair.y = mouseY;

}

Mouse.hide();

movie1.addEventListener(MouseEvent.CLICK,bbb);          /*movie1 is the enemy*/

function bbb(e:MouseEvent)

{

    trace("Win");

}

crosshair.addEventListener(MouseEvent.CLICK,pistolShot);

function pistolShot(e:MouseEvent)

{

    var s:PistolSound = new PistolSound();

    s.play();

}

crosshair.mouseEnabled = false;

i want to my crosshair play the sound effect when it click.

When I remove this code:

crosshair.mouseEnabled = false;

crosshair can play the sound effect but I cannot shoot the enemy.

I can shoot the enemy with the code but it won't play the sound effect.

what code should I use?

thank you

This topic has been closed for replies.
Correct answer kglad

use:

import flash.events.Event;

import flash.events.MouseEvent;

var s:PistolSound = new PistolSound();

crosshair.mouseEnabled = false;

this.addEventListener(Event.ENTER_FRAME,aaa);

this.addEventListener(MouseEvent.CLICK,clickF);

function clickF(e:MouseEvent):void{

s.play();

}

function aaa(e:Event)

{

    crosshair.x = mouseX;

    crosshair.y = mouseY;

}

Mouse.hide();

movie1.addEventListener(MouseEvent.CLICK,bbb);          /*movie1 is the enemy*/

function bbb(e:MouseEvent)

{

    trace("Win");

}

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 28, 2014

use:

import flash.events.Event;

import flash.events.MouseEvent;

var s:PistolSound = new PistolSound();

crosshair.mouseEnabled = false;

this.addEventListener(Event.ENTER_FRAME,aaa);

this.addEventListener(MouseEvent.CLICK,clickF);

function clickF(e:MouseEvent):void{

s.play();

}

function aaa(e:Event)

{

    crosshair.x = mouseX;

    crosshair.y = mouseY;

}

Mouse.hide();

movie1.addEventListener(MouseEvent.CLICK,bbb);          /*movie1 is the enemy*/

function bbb(e:MouseEvent)

{

    trace("Win");

}

C-ReinAuthor
Participant
April 28, 2014

Yey   It's work!!

thank you very much

kglad
Community Expert
Community Expert
April 28, 2014

you're welcome.