我是 ActionScript 的新手,所以我坚持使用它。我需要的是:当鼠标悬停在我的图像上时播放歌曲。我试图这样做,但我得到了错误:
Scene 1, Layer 'actions', Frame 1, Line 45 1120: Access of undefined property soundChannel.
Scene 1, Layer 'actions', Frame 1, Line 46 1120: Access of undefined property soundChannel.
Scene 1, Layer 'actions', Frame 1, Line 74 1120: Access of undefined property des_elefante.
到目前为止,这是我的代码:
import flash.events.MouseEvent;
import flash.media.Sound;
import flash.net.URLRequest;
import flash.media.SoundChannel;
import flash.net.URLLoader;
import flash.events.*;
import flash.display.MovieClip;
var dragArray:Array = [letraE, letraA,letraI,letraO,letraU];
var matchArray:Array = [letraEmatch,letraAmatch,letraImatch,letraOmatch,letraUmatch];
var currentClip:MovieClip;
var startX:Number;
var startY:Number;
matchArray[0].alpha = 0.2;
matchArray[1].alpha = 0;
matchArray[2].alpha = 0;
matchArray[3].alpha = 0;
matchArray[4].alpha = 0;
for(var i:int = 0; i < dragArray.length; i++) {
dragArray[i].buttonMode = true;
dragArray[i].addEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
}
function item_onMouseDown(event:MouseEvent):void {
currentClip = MovieClip(event.currentTarget);
startX = currentClip.x;
startY = currentClip.y;
addChild(currentClip); //leva o clip pra frente
currentClip.startDrag();
stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp, MouseEvent.MOUSE_OVER);
}
function fl_play_sound(event:MouseEvent):void{
var sound = new Sound();
sound.load(new URLRequest("audio_elefante.wav"));
soundChannel = new SoundChannel();
soundChannel = sound.play();
}
function stage_onMouseUp(event:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp);
currentClip.stopDrag();
var index:int = dragArray.indexOf(currentClip);
var matchClip:MovieClip = MovieClip(matchArray[index]);
if(currentClip.hitTestObject(matchClip)) {
//se a combinação é a certa, ele posiciona a o clip da letra no clip do tracinho
currentClip.x = matchClip.x;
currentClip.y = matchClip.y;
//Desabilita pra arrastar já que é o certo
currentClip.removeEventListener(MouseEvent.MOUSE_DOWN, item_onMouseDown);
currentClip.buttonMode = false;
} else {
//se a combinação não é a certa, leva o clip da letra de volta pra posição inicial;
currentClip.x = startX;
currentClip.y = startY;
}
}
letraA.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
letraI.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
letraO.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
letraU.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
letraE.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);
des_elefante.addEventListener(MouseEvent.MOUSE_OVER, fl_play_sound);
function fl_MouseOverHandler(event:MouseEvent):void
{
// Start your custom code
// This example code displays the words "Moused over" in the Output panel.
//trace("Moused over");
// End your custom code
}
我将图像转换为按钮、影片剪辑和图形,但最后一个错误没有任何改变。谢谢