Inn下面的代码我把我的mp3放在这个mxml文件所在的src目录里。所以当swf加载时我可以看到我无法播放mp3的按钮是关于该怎么做的路径
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import flash.display.Sprite;
import flash.display.InteractiveObject;
import flash.display.Sprite;
import flash.media.*;
import flash.net.*;
import mx.controls.Alert;
import mx.controls.Button;
import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
private function clickhandler(event:Event):void
{
var s:Sound = new Sound();
s.addEventListener(Event.COMPLETE, onSoundLoaded);
var req:URLRequest = new URLRequest("sound.mp3");
s.load(req);
}
private function onSoundLoaded(event:Event):void
{
var localSound:Sound = event.target as Sound;
localSound.play();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:Button id="play" label="PLAY" click="clickhandler(event)" />
</s:Application>
答案 0 :(得分:4)
在行中:
var req:URLRequest = new URLRequest("sound.mp3");
您需要指定sound.mp3的完整网址。像
这样的东西var req:URLRequest = new URLRequest("http://server.name.com/path/to/sound.mp3");
如果您不想将路径编译到应用程序中,可以使用Application.url
属性,该属性为您提供加载应用程序的URL。如果你知道你的mp3相对于那里,你可以适当地修改路径并从那里加载。