Open external .swf in another frame or window - actionscript-3

I am trying to link to an external .swf file, which I have done, but it opens as a popup within the main .swf. What I want to do is either have it navigate to a blank frame with the external .swf there or have it open in a new window. How do I achieve this?
Here is the code I have which opens the external .swf:
private function openSWF():void {
cSWFLoader = new Loader();
cSWFPopup = addChild(cSWFLoader);
cSWFLoader.x = cPopX;
cSWFLoader.y = cPopY;
try {
cSWFLoader.load(new URLRequest(cSourceFile));
cSWFLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, SWFLoaded);
}catch (err:Error){
trace("YOU DONE GOOFED", cSourceFile);
trace("Error: ", err);
cSourceFile = null;
}
}
private function SWFLoaded(evt:Event):void{
cSWFLoader.addEventListener(MouseEvent.MOUSE_DOWN, dragSWF);
cSWFLoader.addEventListener(MouseEvent.MOUSE_UP, dropSWF);
cSWFPopup.content.gotoAndStop(cFrameLabel);
cSWFPopup.content.closeBtn.addEventListener(MouseEvent.CLICK, closeSWF);
cSWFLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, SWFLoaded);
}
Thanks in advance

Related

How to handle error dialog boxes in ActionScripts 3

I write some code to check an XML from a URL, it works when Internet connection exist, but when i manually disable internet for test an Error dialog box show, i coudn't handle it with try() catch().
try {
var myXML: XML = new XML();
var XML_URL: String = "https://drive.google.com/uc?export=download&id=0B5pkl4TJ7V0OTFBPanUyMWQxUnM";
var myXMLURL: URLRequest = new URLRequest(XML_URL);
var myLoader: URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event: Event): void {
myXML = XML(myLoader.data);
trace("LOCK CODE: " + myXML.LOCK);
if (myXML.LOCK == 0) {
gotoAndStop(71);
};
}
} catch (e: Error) {
gotoAndStop(71);
trace("FAILED TO CHECK LOCK.");
} finally {
gotoAndStop(71);
trace("FAILED TO CHECK LOCK.");
}
How can i hide this dialog from user?
Add an URLLoader event listener for IOErrorEvent.IO_ERROR
e.g.
myLoader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
function ioErrorHandler(event:IOErrorEvent):void {
trace("ioErrorHandler: " + event);
}
You should handle all events as good measure anyway (e.g. security error, etc.)
The as3 docs example provides a helpful snippet
Ideally you would not only silently trace message, but hopefully display helpful feedback or placeholder content for the user to understand what to expect.

How do you add a link in a swf file?

I am using HTML and I want to embed it and link it to my other webpages. It is in offline mode and I've been searching a lot and found this:
MyClickTagButton.addEventListener(
MouseEvent.CLICK,
function():void {
if (root.loaderInfo.parameters.clickTAG.substr(0,5) == "http:" || root.loaderInfo.parameters.clickTAG.substr(0,6) == "https:") {
navigateToURL(
new URLRequest(root.loaderInfo.parameters.clickTAG), "_blank"
);
}``
}
);
But what I don't understand is how to put my link. Because my website links are only "person.html", "welcome.html", etc. If you know how, please help me. I'll really appreciate it.
You need to open it in Adobe Flash builder (or other swf (Shock Wave Flash) editors) and add the Actionscript 3 to create an event handler for the movie clip and add the URL:
<pre>
ACTIONSCRIPT 3 CODE:
var mySWF:String = "Your SWF movie clip name here";
mySWF.addEventListener(MouseEvent.CLICK, goToUrl);
function goToUrl:void {
var url:String = "Your URL here";
var request:URLRequest = new URLRequest(url);
try {
navigateToURL(request, '_blank');
} catch (e:Error) {
trace("Error occurred!");
}
}
</pre>

Accessing local MP3 id3 properties with ExternalInterface

I need to run a swf inside an Extendscript (java) window in Photoshop. The Extendscript part pops up a Folder Selection dialog and lets user to select a folder. Then it sends the Folder path and the list of the .mp3 files in that folder to the swf file.
The swf can load and play the song
But it can't get the id3 information
The swf is in "Access Network Files Only" mode
I'm pretty sure it is a security issue and wonder if anyone knows of a workaround. Here is my code...
Thanks in advance.
var mp3FileList;
var folder;
var songList;
var songsArray:Array = new Array();
var mp3Array:Array = new Array();
if (ExternalInterface.available) {
ExternalInterface.addCallback("transferSongList", transferSongList);
}
//Extendscript opens a Select Folder dialog
//and sends the folder path and the list of .mp3 files inside the selected folder to this swf
function transferSongList(folder, mp3FileList){
songList=quickReplace(mp3FileList, "%20", " ");
songsArray = songList.split(",");
var mp3File:Sound = new Sound();
mp3File.load(new URLRequest(folder+"/" + songsArray[0]));
mp3File.addEventListener(Event.COMPLETE, parseSound(mp3File));
}
function parseSound(mp3):Function{
return function(e:Event):void {
//IF I REMOVE THE NEXT LINE THE SONG PLAYS
alertbox.text=mp3.id3.songName
mp3.play();
};
}
function quickReplace(source:String, oldString:String, newString:String):String
{
return source.split(oldString).join(newString);
}

Unloading an external .swf within itself in action script 3

I have been trying to look for a method, I've tried numerous code examples none have worked.
This is the code I'm using in my my main .SWF file to load the external .swf file called (Stage4.swf). How can unload this swf file while it's load within the Stage4.swf file?
var child_loader:Loader = new Loader();
addChild(child_loader);
var url:URLRequest = new URLRequest("Stage4.swf");
child_loader.load(url);
child_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, load_completed);
child_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, on_progress);
function load_completed(e:Event):void {
child_loader.x = 0;
child_loader.y = 0;
}
function on_progress(e:ProgressEvent):void {
trace(e.bytesLoaded + " out of " + e.bytesTotal);
}
You should make the child SWF to dispatch a custom Event that will be listened by its parent. Most likely your code snippets don't work because the stack contains the child SWF's code. Something like this:
public static const UNLOAD_SWF:String='unload_swf';
...
function load_completed(e:Event):void {
this.addEventListener(UNLOAD_SWF,doUnload);
// rest of code
}
function doUnload(e:Event):void {
removeEventListener(UNLOAD_SWF,doUnload);
addEventListener(Event.ENTER_FRAME,unloadNow);
}
function unloadNow(e:Event):void {
removeEventListener(Event.ENTER_FRAME,unloadNow);
child_loader.unloadAndStop(); // should work now
}

AS3: Print Job without Print Dialog Box/Print Setup Dialog

Is there a way to print a job without the print dialog box.It will look for the default printer then it will also print all pages.After I click the print button, inside of the movieclip will be print all. Then how can I do it? I don't need AS3 swf not Air if possible..
Here's the code I'm using..
print_btn.addEventListener(MouseEvent.CLICK,printContent);
function printContent(evt:MouseEvent) {
var printJob:PrintJob = new PrintJob();
if (printJob.start()) {
if (content_mc.width>printJob.pageWidth) {
content_mc.width=printJob.pageWidth;
content_mc.scaleY=content_mc.scaleX;
}
printJob.addPage(content_mc);
printJob.send();
}
}
NOTE:
I already used the start2() but this code is for AIR.
It appears there's an answer out there just did some googling:
http://forums.adobe.com/thread/854070
var pj:PrintJob = new PrintJob();
var started:Boolean = pj.start2(null, false);
if(started)
{
pj.addPage(this);
pj.send();
};
pj = null;