Change Banner ClickTag Code to AS3? - actionscript-3

I have been handed a number of Flash (AS3) banners to add ClickTag codes to them and as the documents have been setup as AS3 it does not allow code added to items!
I need help changing the following code to AS3 asap if anyone can help?
on (release) {
getURL (_level0.clickTag, "_blank");
}
I cannot change the document back to AS2 as they have been created through InDesign and the filters don't work if I change them back!
Thanks,
Thomas.

In AS3, the on(event) workflow has been replaced with the event system; and getURL() as been renamed navigateToURL() witch is more clear about what the function does.
// 'import' the necessary resources : If you don't do this, you'll have error while compiling.
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.net.navigateToURL;
// theBanner is the name of your clickable MovieClip. If you add the code in the MovieClip, use 'this' instead
// this line indicate to call "onClick" if MOUSE_UP occurs on theBanner (ie : the user release the mouse hover the MovieClip
theBanner.addEventListener(MouseEvent.MOUSE_UP, onClick);
// The onClick function, how open the new clickTag URL when called
function onClick(e:MouseEvent):void {
// get the clickTag URL (root.loaderInfo.parameters.clickTag), and send it to navigateToURL.
navigateToURL(new URLRequest(root.loaderInfo.parameters.clickTag), '_blank');
}

Related

AddChild to use external SWF has disabled my buttons I had on original Flash file

I have a Flash file (a website header with 5 buttons for 5 links to webpages).
On my actions layer, I added an external SWF file using the addChild object.
Note that I have very basic knowledge of ActionScript and I had to take some help from Google to setup above script.
The external SWF I have brought in using adChild code is working as an overlay on top of my original flash animation but all the buttons I have on original Flash file as website links have now become disabled. Even the mouseOver effects I applied to those 5 buttons are not responding. Below is my AS3 code:
import flash.net.navigateToURL;
import flash.net.URLRequest;
stop();
var swfRequest:URLRequest = new URLRequest("movie/txtOverlay.swf");
var swfLoader:Loader = new Loader();
swfLoader.load(swfRequest);
addChild(swfLoader);
button_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
navigateToURL(new URLRequest("http://www.example.com/link1.asp"), "_self");
}
For the sake of brevity, I have placed just one button's code but you get the idea. Any solution to avoid this?
Thanks ... Syed

making changes to a file i didn't create and now the button wont function

im a simple User interface designer with a bit of knowledge in Flash. I was asked to resize another person's flash file. So i opened the file in ANimate CC. I changed the file dimensions but didn't change the actions of the button. So after i exported it the button function no longer worked. Not sure why since it worked before and now it doesn't. Any ideas how to get the button to work. i need it to go to the url google.org
here is the AS3
import flash.external.ExternalInterface;
// =========================== CLICKTAG STUFF ==================================
// ========================================================================= ====
ct.addEventListener(MouseEvent.CLICK, handleClick);
ct.addEventListener(MouseEvent.ROLL_OVER,handleMouseOver);
ct.addEventListener(MouseEvent.ROLL_OUT,handleMouseOut);
function handleClick(e:MouseEvent):void {
ExternalInterface.call("ctaClick");
trace("clicktag clicked...");
/*var flashVars:Object = LoaderInfo(this.root.loaderInfo).parameters;
if (flashVars.clickTag) {
navigateToURL(new URLRequest(flashVars.clickTag),"_blank");
}
trace("clicked");*/
}
function handleMouseOver(e:MouseEvent):void {
cta.cta.gotoAndPlay("OVER");
cta.gotoAndPlay("over");
}
function handleMouseOut(e:MouseEvent):void {
cta.gotoAndPlay("out");
}
The code that's called when the button is clicked is external in JavaScript:
ExternalInterface.call("ctaClick");
Make sure you test the newly created flash file embedded in the HTML file it is supposed to be embedded in. The flash file is used like an image, it doesn't do much on its own except for some visuals on mouse over.
The functionality is in JavaScript. Without embedding the flash file, the JavaScript is missing and it doesn't do much.

Is there an event I can listen for that will tell when the Flash object was paused?

If I pause the entire Flash object (E.G, swfobject.getObjectById('Object').StopPlay();) is there an event that I can capture within Flash to tell me when this has happened?
AFAIK there is no special Event to listen for that.
But you could use ExternalInterface to do that. Just register a javascriptToActionscriptCall and call it from JS:
AS // swf
import flash.external.ExternalInterface;
ExternalInterface.addCallback("sendStopStatusToAS", callStopFromJavaScript);
function callStopFromJavaScript():void {
trace("SWF stopped by JS");
}
JS
swfobject.getObjectById('Object').StopPlay();
swfobject.getObjectById('Object').sendStopStatusToAS();
Greetings

Adobe CC Flash AS3 Click tag

I recently switched over from Adobe CS6 to Adobe CC. In the new Adobe CC Flash, it no longer supports action script 2. I need to create an AS3, click tag. Is there a universal AS3 clickTag code you know of that is used? I've googled it, but found some unreliable results.
I'm assuming that you mean you want to have a button react to a click? If so, you simply have to create a button object, and then add a listener for that button where you choose 1) the event you want to listen for, in this case a click, and 2) the code you wish to execute when that event is fired, in most cases this is a function call.
For exaxmple, the following code was placed on the first frame of an .FLA:
import flash.events.MouseEvent;
var myButton:SimpleButton = new SimpleButton();
var myButtonSprite:Sprite = new Sprite();
myButtonSprite.graphics.lineStyle(1, 0x555555);
myButtonSprite.graphics.beginFill(0xff000,1);
myButtonSprite.graphics.drawRect(0,0,200,30);
myButtonSprite.graphics.endFill();
myButton.overState = myButton.downState = myButton.upState = myButton.hitTestState = myButtonSprite;
myButton.addEventListener(MouseEvent.CLICK,buttonClickHandler);
addChild(myButton);
function buttonClickHandler(e:MouseEvent):void {
trace("YAY! My Button was clicked!");
}
To give credit where it is due, the code for creating the button dynamically that you see above is showcased here: Create a Button with only code AS3
If you already have a button on your stage that you want to wire up with a click event you simply have to give the button an instance name and then use that instance name in the code. In the following example, the instance name of the button on the stage is myButton:
myButton.addEventListener(MouseEvent.CLICK,buttonClickHandler);
function buttonClickHandler(e:MouseEvent):void {
trace("YAY! My Button was clicked!");
}

loading swf files to buttons all on same page in flash

Good day to everyone!Here is my problem to all that is familiar with Flash. I am creating a portfolio using Flash. It has been sometime since using actionscript and can't figure out this. I have 6 different jpeg that I turned into buttons on 1 project page.What I need is to add different swf files to each button and play in seperate window.The code I used first loaded 1 swf file in same window. I am unable to figure out the code to make all 6 buttons show their individual swf file in a seperate window. Please help I am using trial version of the new Flash CC.
Usually, here on StackOverflow we like to see some code indicating you actually tried something, but let me see if I can help anyway.
Sounds like you are asking how to click a button and have the response be to load another swf into a new window.
To do so, you need to reference an html file with a swf embedded in it, since to see a swf in the browser it needs to be in an html page.
So you would do something like the following:
import flash.events.MouseEvent;
import flash.external.ExternalInterface;
var myUrl = 'http://www.someSiteWhereMyFilesAre.com/myNewSwf.html';
myButton.addEventListener( MouseEvent.CLICK, onClick );
function onClick( e:MouseEvent ):void
{
if( ExternalInterface.available )
{
ExternalInterface.call( 'window.open', myUrl, '', 'width=400,height=300' );
}
}
That method will only work while you have it online. It will not load the file locally.
If you do not care about the size of the window that is opened:
Remove the ExternalInterface import.
add imports:
import flash.net.URLRequest;
import flash.net.navigateToUrl;
Change your onClick function to:
function onClick( e:MouseEvent ):void
{
navigateToURL( new URLRequest( myUrl ), '_blank' );
}