How to read a song using an absolute location in AS3 - actionscript-3

I'm making a music player using AS3, but I'm having one problem; when I try to find a song outside the project folder using the AS3 script it simply doesn't work.
I've searched in the Internet and all the examples I've found used the relative location like this:
loadedSong = new Sound(new URLRequest("music.mp3"));
And it works for me, but with it I need always to have the songs in the root folder of the project. And I want to read them wherever they are without having to duplicate them to the root folder.
I tried to alter the code to use the absolute location like this:
loadedSong = new Sound(new URLRequest("c:\Users\pc\My Music\Artist\Album\music.mp3"));
But it fails with this error: "SecurityError: Error #2000: No active security context."
What am I doing wrong?

This is security restriction of Flash Player. If you need a desktop player, you'd better use Adobe AIR. Otherwise, you can use web server and store files there. Or you can just add allow Flash Player to read from hard drive by adding trusted locations here.

Related

How to load swf created with flipbook maker into flash

I'm trying to load the swf created by 'flip book maker' into my project.
the files created by flipbook maker are
book.swf
framework.swf
I used the following code
var myLoader:Loader = new Loader();
var url:URLRequest = new URLRequest("book.swf");
myLoader.load(url);
addChild(myLoader);``
the framework.swf is linked with book.swf, so it cannot run alone.
When I run the movie it shows the Error #2032, Stream error to framework.swf
book.swf and framework.swf both are in the same directory.They are generated by flip book maker What I needed is to load the book.swf into my project at a particular frame. I need help in AS3 for this purpose.
How to fix it..?
please help me..!
Error #2032 means that your Flash application could not load the framework.swf for some reason (you know this already of course). What you need to find out is why. Possible reasons are: you have the wrong URL, the framework.swf is not in the place you expect, there are crossdomain restrictions on the file you are trying to access ( you did not state where frameworks.swf).
What I would suggest doing is using a web debugging proxy tool like Fiddler (http://www.telerik.com/fiddler) or Firebug (is a Firefox extension) and take a look at the http requests to get more information on your error. You may find out that frameworks.swf is not in the location you expect.
This is just a IOError event triggered by Adobe Flash. Most likely the file just isn't found. Check your path and make sure you place the .swf file in your bin-debug directory if you're doing this from within Adobe Flash Builder

Capture image and voice(use AS3) in flv, save to location, not media server

How can I use AS3 to record video(with voice) by camera? I want it to be saved to location PC of user.
You can try flvRecorder, but what they declare :
The class does not yet support adding sound to the flv-file, this is the next step of development, to enable sound recording and add sound to the flv-file.
and it saves the file directly on the desktop, check the example.
This may be a solution too, that will allow you to record video/sound, give it a try,
Good luck, Cheers !!

Using RequestURL to get to a different folder

I am using AS3 to make a game. I use RequestURL( filename ) to obtain the music I want to play. However, this means the music file has to be in the same folder as the .fla file. How can I use it to get a music file from a different folder? I don't really like having to leave my music outside of a Music folder or properly organised somehow....
EDIT: Should have mentioned this earlier. I tried to use simply something such as "whatever/filename", but I got this security error:
SecurityError: Error #2000: No active security context.
Why?
Have you tried using the flash.media.Sound.load() method yet?
//Make a new sound object
var s:Sound = new Sound();
//Load it
s.load(new URLRequest("someDifferentMusicFolder/loop.mp3"));
//Play it
s.play()
If you are loading it via another method, such as URLLoader + URLRequest, please post your code and we should be able to help a little better.
Generally speaking though URLRequests should allow you to specify different folders, so your problem may not be in the methodology you are using but may be in your implementation? Perhaps you are getting a security error? Whatever it may be, if you post your code we can help you narrow it down.

Pass file from AS3 into embedded AS2 wrapper to load

I have a Flash AS3 application that uses FileReference.browse() to request a SWF from the user. If the chosen SWF is AS3, I'm good to go. However, if it's AS2, I need to load it into an AS2 wrapper first (so my app can alter it). All of these files (including my app and wrapper) are intended to exist locally on the user's machine, but the file they select can exist in any directory. So to be clear: Main application (AS3) -> Wrapper (AS2) -> User's file (AS2)
I know how to get the uploaded file's ActionScript version from the Loader's loaderInfo.actionScriptVersion variable, and that's working correctly. My issue is how to pass the file from the AS3 application to the AS2 wrapper so it can load it.
My first thought was to dump the ByteArray from the FileReference's load() function into a SharedObject "cookie". This method seemed pretty bad from a user-experience point of view, but it seemed most likely to work. However, I've been unable to find any method within AS2 to load the ByteArray as a movie (in fact, AS2 doesn't even seem to have a ByteArray class). So the first potential solution to my problem would be if anyone knew of a method for loading a movie from a ByteArray in AS2.
My second thought was to pass the uploaded file's path to my wrapper via the already-setup LocalConnection bridge, and then just have it load the file from that. However, I can't find any way to get the file's path, and my Googling suggests the security model intentionally prevents it. Not to mention, I'm not sure I can load an arbitrary file from the user's machine.
My "hands up in the air; I give up" solution was to just create separate buttons for loading AS3 and AS2 files (leaving it up to the users to guess which it is!) and have the AS2 button actually within the AS2 wrapper. However, it looks like AS2 doesn't have a file browsing uploading API, and the PHP-hybrid solutions I've found aren't an option (because this is meant to be run locally).
So, I would be eternally grateful if anyone could point me in the right direction for solving any of these three roadblocks. Alternative workarounds are of course welcome.
(Edit)
Ok, I found the documentation for AS2's version of the FileReference class. It supports the same file-browsing capability, but does not support directly loading the selected file into the SWF.
However, the security sandbox doesn't seem as strict for local files as I expected, and it looks like I can load any SWF on the user's machine once I have a path to it. So I should be able use JavaScript and an HTML form with a file input to get and pass the file path to my application. It's not ideal having to do all of this from within a web browser, but it should work. If it turns out satisfactorily I'll submit it as an answer.
(Edit 2)
Scratch the HTML-form idea. Looks like the path is hidden from JavaScript for the same reasons Flash hides it. The only option I can think of now is to have the user copy and paste the path to the file...
After reading over your post, you may be able to retry one of your previous attemps with some new information. Actionscript 2 DOES have a method for looking up files from a browser, same as AS3 does. AS2 also has a FileReference class. Check out the documentation here:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00001040.html
Also, here is a tutorial:
http://markshu.ca/imm/flash/tutorial/fileReference.html
Well, all of my other leads have dried up, so I'm submitting the two answers that will actually work, although neither is ideal:
A) Use Adobe AIR, which will give more access to the filesystem (such as for getting path info) at the cost of requiring the separate AIR runtime to be installed.
B) Have the user enter the path to the file themselves (cumbersome for the user)

Flexbuilder won't launch...arrrgh!

In a panic since I'm trying to meet a deadline so appreciate any feedback on this.
For some reason, Flexbuilder 3 on my mac won't launch, crashes on startup.
I've never experienced this before.
Checked the .log file and what seems to be the problem is the following
/Users/foo/Library/Preferences/Macromedia/Flash Player/#Security/FlashPlayerTrust/flexbuilder.fbr (No such file or directory)
WTF is the flexbuilder.fbr???
Googled but not much luck.
The only thing I've done that might have caused this is change flash player versions system wide using the official flash player uninstaller...but obviously this should not happen
Any feedback appreciated...
It's hard to know where it went, but this file just contains a number of paths of 'trusted' locations for the Flash Player. Normally when you create a new workspace in FlexBuilder it adds the workspace location to this file, or if you create a project outside of the workspace it adds the project path.
It's surprising the absence of that file would keep FlashBuilder from launching though.
Ok, my workaround was to simply create an empty text file called flexbuilder.fbr in the location of the missing file.
But still would like to know the purpose of this file and how it went MIA...