Android & Flash Professional CS 5 Adobe Air Audio: Stream Error - actionscript-3

I have the following code:
import flash.media.Sound;
import flash.net.URLRequest;
function playBase():void
{
var urlRequest:URLRequest = new URLRequest("mybase.mp3");
var sound:Sound = new Sound();
sound.load(urlRequest);
sound.play();
}
playBase()
I have mybase.mp3 into my LIBRARY section, but the DEBUG OUTPUT show me:
Error #2044: Unhandled IOErrorEvent:. text=Error #2032: Stream Error.
Why?

URLRequest is used to load an external file, so either
1: save the mp3 file as "mybase.mp3" to the same directory that is running your Flash/AIR App, instead of in your library.
OR
2: In your library right click on the mp3 file > properties > and export for actionscript using a name like MyBaseSound. Once you do that you should be able to reference the sound like a class, something like:
var s:MyBaseSound = new MyBaseSound();
s.play()
EDIT
If going with option 1 you likely will want to go to Publish Settings then to your Android Settings area and under included files add that file. This should add it to your app bundle / package. (In CS6 it is the little wrench icon, but in CS5 I don't recall the exact steps to get there for Android, but I know the iOS settings page has a similar included files option.)

Related

ActionScript 3 - sound mp3 is not played without error

Help me, I use Adobe Flash CS3 Professional.
// i have try using this import, but still not work
/*import flash.events.Event;
import flash.media.Sound;
import flash.net.URLRequest;
*/
// here is the code
var req:URLRequest=new URLRequest("music.mp3");
var snd:Sound=new Sound();
snd.load(req);
var chan:SoundChannel=snd.play();// not work using 'snd.play(1);' too
chan.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
function onPlaybackComplete(event:Event){
trace("Musik Complete");
}
When i run the swf or ctrl+enter, the output Musik Complete without any sound played, but the animation still played. For the animation i just create simple twin motion.
i work on this directory
C:/flash/example.fla
C:/flash/example.swf
C:/flash/music.mp3
I have try to import music.mp3 into the library too.
Note: I get the example from my friend(.swf, .fla, .mp3). I play the .swf that shared by my friend and work, but when i try to create by my self, is not work. So, i think music.mp3 was fine to use for Flash. Here is my friend code:
var Audio:musik = new musik();
var chan:SoundChannel = new SoundChannel();
// play
chan=Audio.play();
// stop
chan.stop();
// i am so confuse i run my friend project and work fine (sound and other), if i write from scrap even i write the same code, there is an error, and this the error:
// 1046: Type was not found or was not a compile-time constant: musik.
// 1180: Call to a possibly undefined method musik.
I just watch on youtube, i missing one step.
In library, open properties of music.mp3 and give it class name.
So, we can call the class using this var Audio:musik=new musik();.
Then, create the Sound Channel.
At least, function to play and stop using this:
//play
chan=Audio.play();
// stop
chan.stop();

Flash AS3 - SoundChannel error #1009

I'm a bit of a Flash newb so apologies if this is a simple issue or fix.
Anyways I'm having problems with some functions. I've noticed I'm getting error 1009 only on functions that attempt to stop a sound channel. Here's some of the code:
This is one the first frame of the first scene, just setting up my channels. All my sounds are done here too but I don't think those are a problem.
import flash.media.Sound;
import flash.media.SoundChannel;
var musicChannel:SoundChannel = new SoundChannel();
var speechChannel:SoundChannel = new SoundChannel();
var sfxChannel:SoundChannel = new SoundChannel();
And here's an example of one of the buttons that causes the 1009 error:
function goHome(e:MouseEvent):void {
speechChannel.stop();
sfxChannel.stop();
musicChannel.stop();
gotoAndPlay(2, "TitleScreen")
}
home.addEventListener(MouseEvent.CLICK, goHome);
Now what really confuses me is that this same code ran perfectly last night on my computer. I went to test my .swf on the computers at my college and my animation froze, so I checked in Flash and this is what I got.
I'm also getting the same 1009 error on some TweenMax stuff. And yes I did import everything necessary and all files that are required for these functions to run are in the root directory of the .fla file. I know this because, as with the other error, this stuff worked on my computer at home perfectly. I am running the exact same .fla file and code file I saved on my computer and I do have the 'com' folder and 'greenstock' swc files in the same directory as my .fla, just like on my PC, yet I'm stilling seeing 1009 with this:
import com.greensock.TweenLite;
import com.greensock.TweenMax;
TweenMax.to(musicChannel, 2, {volume:0});
Again this line is referencing a sound channel, so I'm 99% sure it's the root of these problems. I can swap out 'musicChannel' in this piece of code with 'Music1' (a sound declared in the first frame with the channels) and it stops the music fine, but whenever I try to stop sound channels it craps out on me.
Again sorry if this is really simple to fix but I'm quite confused because it was working fine last night. The Flash Player could be outdated but it's Adobe Flash Player 11 so I don't know if that would be the problem. Right now I'm at college so I don't know what version I have at home.
Thanks for your time.
SoundCahnnel can be null and when they are you can't try to tween their property. An easy way to deal with that is to check whether they are null or not:
if(musicChannel)
{
TweenMax.to(musicChannel, 2, {volume:0});
}
Also SoundChannel objects are generated only when a Sound object play method is called so there's no need to instantiate them:
var musicChannel:SoundChannel = new SoundChannel();//irrelevant piece of code
var musicChannel:SoundChannel;//correct

AS3:loading XML is not working after exporting the air file?

import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
names();
function names()
{
var url:URLRequest = new URLRequest("http://artbeatmedia.net/application/xmlkpisname.php?username=adel_artbeat&password=ADL1530");
url.contentType = "text/xml";
url.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.load(url);
loader.addEventListener(Event.COMPLETE, onLoadComplete);
}
function onLoadComplete(event:Event):void
{
trace('good');
}
i used adobe air to load xml using as3,this code works only in the .fla file,but when i export the .air file it does not work.
if you export a program, trace messages won't be visible.
you can still use MonsterDebugger, but thats a security hazard.
Vizzy tracer will still capture trace calls from an Air app. Get Vizzy from Google code
I tried your code with no modifications just now and it worked just fine, so I suppose your problem is just a failed trace out. Have a go, Vizzy shows even traces from within Flash IDE, so see what happens. If it still fails, then it might be some connection/permission issue.
Are you including the XML file when you publish the AiR app? Happened to me once, forgot to include the file in the publish dialogue....an hour of my life I'll never get back.

Compiling SWF runtime from adobeAir application

I have problem in creating swf file runtime from an adobe air application. For example I create animation using https://github.com/jamesflorentino/Flip-Planes-AS3, I have converted the Sprite extension to MovieClip, the animation runs very good. Now I would like to make the animation could be save as swf file by user.
I have tried as3swf with script like this:
private function createSwf():void{
//let make example the Main class is taken from github above
var _main:Main = new Main();
// in this case i use AS3SWF plugin
var _swf:SWF = new SWF(_main.loaderInfo.bytes);
// this is for copy byteArray from the _swf convertor
var buffer:ByteArray = new ByteArray();
_swf.publish(buffer);
saveToDesktop(buffer);
}
private function saveToDesktop(_ba:ByteArray):void{
// create the file on the desktop
var myFile:File = File.desktopDirectory.resolvePath("demo.swf");
// create a FileStream to write the file
var fs:FileStream = new FileStream();
// add a listener so you know when its finished saving
fs.addEventListener(Event.CLOSE, fileWritten);
// open the file
fs.openAsync(myFile, FileMode.WRITE);
// write the bytearray to it
fs.writeBytes(_ba);
// close the file
fs.close();
}
private function fileWritten(e:Event):void{
trace("new swf file is created");
}
After all those process i got generated swf in my desktop folder with name demo.swf but when i open the file, it is only a white background with error message:
VerifyError: Error #1014: Class flash.events::NativeWindowBoundsEvent could not be found.
at flash.display::MovieClip/nextFrame()
at mx.managers::SystemManager/deferredNextFrame()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:278]
at mx.managers::SystemManager/preloader_preloaderDocFrameReadyHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\managers\SystemManager.as:2627]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.preloaders::Preloader/timerHandler()[E:\dev\4.y\frameworks\projects\framework\src\mx\preloaders\Preloader.as:515]
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
please help me what is the best way to create swf file runtime, both from script side or command line side as long as not server side because it is desktop application.
Many Thanks
Creating a SWF at runtime is not going to be the same as taking an in memory byte array representation of an animation and saving it with a SWF extension.
If you want to build a SWF from AIR; you may consider bundling the Flex Framework with your application and use a NativeProcess to trigger mxmlc to generate a SWF. You'll need source code [or SWCs] to do this, though, it won't work with already compiled assets/classes from your running application.
Or you may want to review the file format for a SWF and go about creating it manually from your AIR application. I have no doubt this is possible, but I do not expect it to be trivial.

How to send data from flash player into an external executable through a pipe

I want to send data generated by a flash module into an external executable in windows. From what I've learnt about interprocess communication, I think it is appropriate to use pipes in this case. I am using Flash professional CS5 and when a 'trace' command is used in actionscript the ouput will be displayed in the output window in flash professional. I think Flash pipes the data into the output window and if so is it possible to obtain the handle to that pipe. Is there a way by which I can write the output from flash player itself when the trace commands are executed or the data generated on an event directly into the buffer of a pipe.
Please help me out.
Thanks in advance.
I did some tricks using a Flash Badge, AIR app. and C# console app..
We can send params to an AIR app. from BADGE and receive it using:
protected function onInit(event:FlexEvent):void{
NativeApplication.nativeApplication.addEventListener(BrowserInvokeEvent.BROWSER_INVOKE, onBrowserInvoke);}
protected function onBrowserInvoke(e:BrowserInvokeEvent):void{
//reading args
var a:String = e.arguments[0];
//Now we can run *.exe from windows using:
if(NativeProcess.isSupported)
{
var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = File.applicationDirectory.resolvePath("ExecutableApp.exe");
nativeProcessStartupInfo.arguments.push(a);
var process:NativeProcess = new NativeProcess();
//dispatched when the process will be finished
process.addEventListener(NativeProcessExitEvent.EXIT,onProcessDone);
//run
process.start(nativeProcessStartupInfo);
}
else Alert.show("Native process are not supported\nPrinter settings may be wrong!");
}
It's a long way, but certainly works! At least for me it worked.