gpt4 book ai didi

actionscript-3 - 听起来不起作用

转载 作者:行者123 更新时间:2023-12-03 02:08:55 26 4
gpt4 key购买 nike

package 
{

import flash.display.MovieClip;
import flash.events.*;
import flash.media.Sound;
import flash.net.URLRequest;

public class untitledCode extends MovieClip
{
private var speed:Number = 5;
private var req:URLRequest = new URLRequest("C:\Users\Anirudh_2\Documents\Game(Fl)\Sword Slash.mp3");
private var SoS:Sound = new Sound(req);
public function untitledCode()
{
mcPlayer2.addEventListener(Event.ENTER_FRAME, P1hit);
SoS.addEventListener(Event.COMPLETE, onCompletion);
SoS.load(req);
}
private function onCompletion(event:Event):void
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, whenKey1);
stage.addEventListener(KeyboardEvent.KEY_DOWN, whenKey2);
}
private function whenKey1(event:KeyboardEvent):void
{
if (event.keyCode == 38)
{
mcPlayer1.y -= speed;
}
if (event.keyCode == 40)
{
mcPlayer1.y += speed;
}
if (event.keyCode == 37)
{
mcPlayer1.x -= speed;
}
if (event.keyCode == 39)
{
mcPlayer1.x += speed;
}
if (event.keyCode == 96)
{
mcPlayer1.play();
SoS.play();
}

}
private function whenKey2(event:KeyboardEvent):void
{
if (event.keyCode == 87)
{
mcPlayer2.y -= speed;
}
if (event.keyCode == 83)
{
mcPlayer2.y += speed;
}
if (event.keyCode == 65)
{
mcPlayer2.x -= speed;
}
if (event.keyCode == 68)
{
mcPlayer2.x += speed;
}
if (event.keyCode == 90)
{
mcPlayer2.play();
}

SoS.play();
}

private function P1hit(event:Event):void
{
if (mcPlayer1.x >= (mcPlayer2.x - (mcPlayer1.width - 35)))
{
//trace("WOW")
//mcPlayer1.x >= (mcPlayer2.x - (mcPlayer1.width - 35))
}
else if (mcPlayer1.hitTestObject(mcPlayer2))
{
//trace("All Good");
}
}
}

}

我收到一条错误消息:

"Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful. Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error. at untitledCode()".



声音文件被声明为SoS。

最佳答案

  • 您不需要调用load()函数:

    If you pass a valid URLRequest object to the Sound constructor, the constructor automatically calls the load() function for the Sound object. If you do not pass a valid URLRequest object to the Sound constructor, you must call the load() function for the Sound object yourself, or the stream will not load.

    Once load() is called on a Sound object, you can't later load a different sound file into that Sound object. To load a different sound file, create a new Sound object.



    Reference

    因此您的代码应类似于:
    private var SoS:Sound = new Sound(req);
    public function untitledCode()
    {
    mcPlayer2.addEventListener(Event.ENTER_FRAME, P1hit);
    SoS.addEventListener(Event.COMPLETE, onCompletion);
    //SoS.load(req);
    }
    或:
    private var SoS:Sound = new Sound(/* req */);
    public function untitledCode()
    {
    mcPlayer2.addEventListener(Event.ENTER_FRAME, P1hit);
    SoS.addEventListener(Event.COMPLETE, onCompletion);
    SoS.load(req);
    }
  • 您应该在路径中使用正斜杠而不是反斜杠:“C:/ Users / Anirudh_2 / Documents / Game(Fl)/ Sword Slash.mp3”
  • 关于actionscript-3 - 听起来不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25830634/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com