Actionscript-3 file access from SWF embedded into PDF - actionscript-3

My SWF accesses a text file with the following code.
var myTextLoader:URLLoader = new URLLoader();
myTextLoader.addEventListener(Event.COMPLETE, onLoaded);
myTextLoader.load(new URLRequest("C:\\Users\\Chris\\Desktop\\moves.txt"));
I have now embedded my SWF inside a PDF and it stops working, is there a way to do this?

Related

Unload SWF File in a Same Button that Load the External File to Minimize Loading Time

I have two SWF files. First one is home.swf and the second one is menu.swf. Each SWF file has a button that load external SWF file.
This is the code inside home.swf file:
stop();
menu_btn.addEventListener(MouseEvent.CLICK, func_menu);
function func_menu(e:MouseEvent):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("menu.swf"));
}
function onComplete(e:Event):void {
var movie:* = LoaderInfo(e.currentTarget).content;
stage.addChild(movie);
}
This is the code inside menu.swf file:
stop();
home_btn.addEventListener(MouseEvent.CLICK, func_home);
function func_home(e:MouseEvent):void {
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("home.swf"));
}
function onComplete(e:Event):void {
var movie:* = LoaderInfo(e.currentTarget).content;
stage.addChild(movie);
}
If I click the buttons numerous times, the SWF files gets longer time to load. I notice that those code doesn't unload files. What code do I need to unload the previous SWF files?
I'm new in actionscript. Please go easy on me.
I understand from the question that it's highly likely that you'll switch between the SWFs often (loading home and unloading menu, and vice versa).
I suggest you create a container SWF, which will load both SWFs, and save references to the loaders / their content on load complete.
Once both are loaded, simply call addChild() and removeChild() to swap them.
In case you want to trigger the swap from within the SWFs, you can dispatch an event when clicking on the buttons created in them, and listen to dispatched events in the container SWF.
That way you can swap them as many times as you'd like in an instant without having to reload them every time, plus you avoid constantly allocating and deallocating memory.

How make with AS3 downloading MP3 files in the background mode and plays it?

I need help with AS3 make downloading MP3 files in the background mode. Man goes to my site and it will automatically load MP3 file on his computer and plays it. I read these examples here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html but do not know how to do it? Prompt what code and how to use it properly?
You can directly load a Sound object with an URLRequest instead of using a separate Loader or URLLoader. A code could look like this:
// this code should reside in a function somewhere
var request:URLRequest = new URLRequest("http://your.site.com/your.mp3");
var sound:Sound = new Sound(request;
sound.addEventListener(Event.COMPLETE, completeHandler);
// this function should be at top level anyway
private function completeHandler(event:Event):void
{
var loadedMP3:Sound = Sound(event.target);
if (loadedMP3) loadedMP3.play();
}
Extra error handling is up to you.

Actionscript - How to import swf with an html wrapper to timeline?

Afternoon,
I have a multiple choice quiz generated by a third party software which can export the quiz as an swf file.
The swf file comes with an html wrapper.(index.html)
It also creates a data folder that has a javascript file. No fla file is given.
My problem is...I'm working with flash cc to create a navigation menu so you click a button a video plays..then at the end of video you click and you take the quiz.
I am able to have the video stop and assign a click to it...What do i need to do to have the button call the swf file(when imported by itself comes up blank) or the index.html so the quiz will show up inside the timeline of the fla that i am working with?
I'm making a free training DVD for my students.
You can use the class Loader:
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("file.swf");
var loaderContext:LoaderContext = new LoaderContext(false,ApplicationDomain.currentDomain, null);
loader.load(url, loaderContext);
When it's finished load, you can use it in you own actionscript file

Resize embeded FLIPBOOK in a .fla file

I’m having the same problem every time I want to resize the Swf file of any flipbook (or Swftools template) as an external load in my main Flash website, through AS3. They always take the whole surface of the screen automatically, even if I’m using the same code for setting external proportions in general… That doesn’t work. I suppose I have to force the internal and encrypted code in those Swf files, because flipbook templates never provide a .fla files or any AS3 (in html it’s ridiculously easy, but unfortunately my entire site is flash-based). Any help? Thanks in advance!
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,f);
loader.load(new URLRequest("flipbook.swf"));
function f(e:Event):void{
addChild(loader);
//////RESIZE EXTERNAL LOAD///////
loader.width = 700;
loader.height = 500;
}
////SET LOCATION EXTERNAL LOAD/////
loader.x = 100;
loader.y = 200;

Flash AS3 Read Text File

I simply need to read a text file from my computer, or a website. I've tried everything, and nothing so far has worked. It should be extremely simple, just reading a text file from a website, like http://foo.com/foo.txt/, but I've tried everything, and nothing I have seen on Google comes even close to working. I don't care how I get the problem solved, as long as I can do it.
To read the content of a file, just use a URLLoader:
// Define the path to the text file.
var url:URLRequest = new URLRequest("file.txt");
// Define the URLLoader.
var loader:URLLoader = new URLLoader();
loader.load(url);
// Listen for when the file has finished loading.
loader.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void
{
// The output of the text file is available via the data property
// of URLLoader.
trace(loader.data);
}
For stuff on another domain, you will need to have a crossdomain file hosted to be able to load the text file.