The previous code tutorial explains how to make a flash movie
automatically jump to a web page when it reaches a specific frame in
your timeline. Here I will show you have to make a button that will
allow the user to jump to a webpage when they choose to. This is the
kind of interaction that you would build into a banner add, or any
other time you would like to create a user initiated action.
The complete code block looks like this:
stop();
var myWebSite01:URLRequest = new URLRequest("insert URL here");
myWebLink01_btn.addEventListener(MouseEvent.CLICK, gotoWebLink01);
function gotoWebLink01(myEvent:MouseEvent) {
navigateToURL(myWebSite01);
}
To make this code work all you would have to do is insert your URL into the "insert URL here" space and change the myWebLink01_btn text to reflect your button's instance name.
The specifics of each bit of code are explained below:
/*The following stop function is used to stop the playhead from advancing and therefore repeating the movie.
Depending on the type of project you are creating you may want it to repeat and can therefore just skip this line of code.
*/
stop();
/*
1: As with any external link you have to create a URLRequest
variable to store the URL that you will want to navigate to later. As
with all variable declarations the left side of the equation states the
name of the variable (here the name myWebSite01 is used) and the type
of data (or data type) the variable will hold. The right side of the
equation instanciates the new variable and sets its value (the URL it
holds). You would have to create a separate URLRequest variable for
each web address you want to use.
*/
var myWebSite01:URLRequest = new URLRequest("http://www.agitraining.com/eval");
/*
2:
In order for an object on the stage to respond to the user you have to
attach an event Listener to it. An event listener will wait for a
specific event to occur and then it triggers a function.
Note: A
LIstener is similar in concept to the reciever on a cell phone, it is
completely passive until someone calls you, then it triggers the ringer.
3:
The addEventListener method is added to the instance of a movieClip or
Button on your stage. Every object on yoru stage has methods and
properties, a method is something that an object can do while a
property is something that it possesses.
Note: If an object on the
stage can be compared to a human being then out ability to jump up and
down would be a method while our height and weight would be properties.
4:
The addEventListener method takes two parameters the irst is the type
of event that it listenes for (in this case the click MouseEvent) and
secondly the name of the function that it is going to fire off when the
Event is found to be true. The Function name in this case is
gotoWebLink01, this is a completely arbitrary name and this function
will be declared in teh next step.
*/
myWebLink01_btn.addEventListener(MouseEvent.CLICK, gotoWebLink01);
/*
5: Functions are declared using the function keyword followed
by the name of the custom function that you want to create. A function
that is going to be triggered by an eventListener must be prepared to
receive information about the event that triggered it from this
listener. This is the information that is placed inside of the
parenthesis after the function name. In this case myEvent is an
internal variable that is used ot hold this information once it is
passed from the listener to the function.
6: Once the function is
triggered whatever commands are located between the braces are
initiated. In this case that is the navigateToURL function.
*/
function gotoWebLink01(myEvent:MouseEvent) {
navigateToURL(myWebSite01);
}
Technorati Tags: Adobe Flash, Actionscript 3.0, Actionscript, Flash
_______________________
Monday, June 29, 2009
Automatically Jump to a webpage using Actionscript 3.0 in Adobe Flash
With the creation of Actionscript 3.0 many things changed. Once familiar code is now long gone, and old concepts have been completely revamped. The once familiar web link is now a thing of the past replaced by new commands and methodology. The tutorial below is useful for created a Flash movie that will automatically jump to a web page as often occurs at the end of an animated intro or presentation.
All of the code here should be placed in the last frame of your timeline. It is standard practice to place all code on it's own layer called actions. This makes it easier to find and edit the code in your project when you come back to it at a later date.
The full code block looks like this:
stop();
var myLink:URLRequest = new URLRequest("insert URL here");
navigateToURL(myLink);
//First you will want to stop the timeline to prevent the animation from looping. If you don't do this the animation will repeat as will the command to open a new web page. I once crashed a computer because I forget about this fact and it ended opening p hundreds of web page windows, one after the other.
stop();
/*
1: All links to external content must be stored in a variable before they can be used. This is true if you want to import data from an external file like a text (.txt) or html (.html) file or as we do here to navigate to an external website.
2: The var keyword is used to declare a variable. Here the arbitrary name myLink is used as the variable name. All variables should be datatyped, that is the type of data that they are going to contain needs to be explicitly stated. As seen in the code below datatypes are connected to the variable names via a colon.
3: On the right side of the variable declaration the new keyword is used to instantiate the myLink variable. This establishes it as an instance of the URLRequest class. If you aren't familiar with them classes are the many different types of objects that you have access to in Flash. Other examples of classes would be SimpleButtons and MovieClips. The actual URL you would like this varaible to hold are placed inside the parenthesis on the right side of the equattion.
*/
var myLink:URLRequest = new URLRequest("insert URL here");
/*
1: Once the myLink variable has been declared it can be used. The code here is the function that actually navigates to the web page. Since this code is written all alone in the keyframe it will execute the moment that playhead encounters it instead of in response to some user initiated event like a button click. Note that the URLRequest variable that was declared about is placed inside the parenthesie of the navigateToURL function here.
*/
navigateToURL(myLink);
Technorati Tags: flash, Actionscript 3.0, actionscript, weblink, Adobe Flash
All of the code here should be placed in the last frame of your timeline. It is standard practice to place all code on it's own layer called actions. This makes it easier to find and edit the code in your project when you come back to it at a later date.
The full code block looks like this:
stop();
var myLink:URLRequest = new URLRequest("insert URL here");
navigateToURL(myLink);
//First you will want to stop the timeline to prevent the animation from looping. If you don't do this the animation will repeat as will the command to open a new web page. I once crashed a computer because I forget about this fact and it ended opening p hundreds of web page windows, one after the other.
stop();
/*
1: All links to external content must be stored in a variable before they can be used. This is true if you want to import data from an external file like a text (.txt) or html (.html) file or as we do here to navigate to an external website.
2: The var keyword is used to declare a variable. Here the arbitrary name myLink is used as the variable name. All variables should be datatyped, that is the type of data that they are going to contain needs to be explicitly stated. As seen in the code below datatypes are connected to the variable names via a colon.
3: On the right side of the variable declaration the new keyword is used to instantiate the myLink variable. This establishes it as an instance of the URLRequest class. If you aren't familiar with them classes are the many different types of objects that you have access to in Flash. Other examples of classes would be SimpleButtons and MovieClips. The actual URL you would like this varaible to hold are placed inside the parenthesis on the right side of the equattion.
*/
var myLink:URLRequest = new URLRequest("insert URL here");
/*
1: Once the myLink variable has been declared it can be used. The code here is the function that actually navigates to the web page. Since this code is written all alone in the keyframe it will execute the moment that playhead encounters it instead of in response to some user initiated event like a button click. Note that the URLRequest variable that was declared about is placed inside the parenthesie of the navigateToURL function here.
*/
navigateToURL(myLink);
Technorati Tags: flash, Actionscript 3.0, actionscript, weblink, Adobe Flash
Subscribe to:
Posts (Atom)