How do you add a link in a swf file? - html

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>

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.

Open external .swf in another frame or window

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

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;

Actionscript 3 Sound ioError Problem

i am having trouble with sound. i am loading it dynamically, url comes from flashvars.
App is working actually but stil gives error, unhandled ioError. but i already handled it.
`
var sound:Sound = new Sound()
try{
sound.load(new URLRequest(req));
} catch(e:IOError){
trace("catch ioerror");
}
sound.addEventListener(IOErrorEvent.IO_ERROR, function(evt:IOErrorEvent):void { trace("error:",evt) } );
sound.addEventListener(Event.COMPLETE, function(e:Event):void{
channel = sound.play(0,int.MAX_VALUE);
});`
Just to rule it out, try commenting out the line channel = sound.play(0,int.MAX_VALUE); perhaps it is this that is throwing the error and not the load, and you have no catch around this.
Try a neater approach in terms of code, might just have issues with your layout and such:
var request:URLRequest = new URLRequest(req);
sound.load(request);
sound.addEventListener(IOErrorEvent.IO_ERROR, _ioError);
sound.addEventListener(Event.COMPLETE, _complete);
function _ioError(e:IOErrorEvent):void
{
trace("File was not found");
_removeListeners();
}
function _complete(e:Event):void
{
channel = sound.play(0,int.MAX_VALUE);
_removeListeners();
}
function _removeListeners():void
{
sound.removeEventListener(IOErrorEvent.IO_ERROR, _ioError);
sound.removeEventListener(Event.COMPLETE, _complete);
}

Actionscript button linking issue

So this doesn't make any sense. I have actionscript in a flash-based button menu, and one of the buttons is linking to the wrong page, and i cannot figure out why. Here is the actionscript:
var myURL1:URLRequest = new URLRequest ("home.html");
home_btn.addEventListener(MouseEvent.CLICK, home_btnEventHandler);
function home_btnEventHandler(event:MouseEvent):void
{
navigateToURL(myURL1, "_self");
}
var myURL2:URLRequest = new URLRequest ("featuredwork.html");
work_btn.addEventListener(MouseEvent.CLICK, work_btnEventHandler);
function work_btnEventHandler(event:MouseEvent):void
{
navigateToURL(myURL2, "_self");
}
var myURL3:URLRequest = new URLRequest ("featuredartist.html");.
artist_btn.addEventListener(MouseEvent.CLICK, artist_btnEventHandler);
function artist_btnEventHandler(event:MouseEvent):void
{
navigateToURL(myURL3, "_self");
}
var myURL4:URLRequest = new URLRequest ("artists.html");
members_btn.addEventListener(MouseEvent.CLICK, members_btnEventHandler);
function members_btnEventHandler(event:MouseEvent):void
{
navigateToURL(myURL4, "_self");
}
var myURL5:URLRequest = new URLRequest ("events.html");
events_btn.addEventListener(MouseEvent.CLICK, events_btnEventHandler);
function events_btnEventHandler(event:MouseEvent):void
{
navigateToURL(myURL5, "_self");
}
var myURL6:URLRequest = new URLRequest ("/blog/index.php");
blog_btn.addEventListener(MouseEvent.CLICK, events_btnEventHandler);
function blog_btnEventHandler(event:MouseEvent):void
{
navigateToURL(myURL6, "_self");
}
Now, when I click on blog_btn, it is sending me to the "events" page. It makes no sense. Does anybody have any idea?
Fairly easy to spot: you have
blog_btn.addEventListener(MouseEvent.CLICK, events_btnEventHandler);
when you mean
blog_btn.addEventListener(MouseEvent.CLICK, blog_btnEventHandler);
notice the second parameter.
You've bound the events handler to the blog_btn click - change the last block to point to the correct handler:
blog_btn.addEventListener(MouseEvent.CLICK, blog_btnEventHandler);