
I’ve been thinking about this blog and what kind of content I want to be creating for the world and yes, you. I really enjoy creating working tutorials and open source project or components available to download and learn from. I make these available so that you are able to pick it apart and hopefully learn something from it. And in the best of scenarios it helps you solve some problem in one of your own projects, or you contact me and are able to teach me a better way I could have done it (my personal favorite). There are no shortcuts to this kind of stuff. Learning is a process, and the way I learn (especially when it’s related to flash) is to get my hands on something that already works and pick it apart. So that’s what I try to provide in my “tutorials”- I use the term loosely because, they aren’t really walkthroughs per say, but more working examples for you to look into and see how it has to (or at least could) fit together and work. I have really enjoyed the direction I’ve gone with the blog, and to get to my point…
I have also learned a lot of what I know from books. Reading books and understanding the whys to all the ways things are done in actionscript has helped me a lot. It may have been an epiphany, but I thought – why not share the ones that have made the biggest support for me, or at least list the books that sit the closest to my keyboard when I am working through a project.
So books are good. I will be continuing with my tutorials and open source working examples and put up as much code as I can, but I want to also talk about where I learn some of the things I learn.
So if you follow the blog, thanks! You’ll start to see a larger variety in posts. Dare I put this in writing but I’m also trying to increase the frequency of posts. I’ve been pretty good at getting at least one post a week, so I’ll try to bump it up to at least 1 and a half posts a week
Go ahead and subscribe to my feed if you want to be sure not to miss any of them, and please jump back to the posts when it’s interesting and let me know, comment with any books that have helped you better understand you specialty.
asfunction (TextEvent.LINK) Tutorial for AS3 | Flash HTML Link to call actionscript function | Tutorial
Overview
Earlier I wrote a tutorial article about asfunction in as2. Now that I’ m into as3, surprise surprise asfunction has been depreciated and now to replace it is the LINK TextEvent. Dispatched when a user clicks a hyperlink in an HTML-enabled text field, where the URL begins with “event:”. The remainder of the URL after “event:” will be placed in the text property of the LINK event.
This differs from the asfunction method in that we must add an event listener (addEventListener) to the textField object, the event listener specifies which function will be called in the event of a link click and there is no way to send arguments along with the event (AFAIK). But it’s easy enought to use one link event function for all your link events and put in a simple switch statement to coordinate the desired results…
Steps
Example
Actionscript
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"Here's a normal link to <a href='http://bloc.circlecube.com'>circlecube</a> putting the link into the href attribute like normal!\n"+
"<a href='event:clickLink'>Click this circlecube</a>, to see the text event link in action! \n"+
"And some more links that don't go anywhere, but they do call functions in actionscript. "+
"Click this to move <a href='event:moveUp'>UP</a>, click me move back "+
"<a href='event:moveDown'>DOWN</a>.\n"+
"Also, one last example <a href='event:testing'>click for a trace test</a>";
//create and initialize css
var myCSS:StyleSheet = new StyleSheet();
myCSS.setStyle("a:link", {color:'#0000CC',textDecoration:'none'});
myCSS.setStyle("a:hover", {color:'#0000FF',textDecoration:'underline'});
myHTML.styleSheet = myCSS;
myHTML.htmlText = myHTMLText;
myHTML.addEventListener(TextEvent.LINK, linkHandler);
function linkHandler(linkEvent:TextEvent):void {
switch (linkEvent.text) {
case "clickLink":
clickLink();
break;
case "moveUp":
moveUp();
break;
case "moveDown":
moveDown();
break;
default:
giveFeedback(linkEvent.text);
}
}
//function to be called from html text
function clickLink():void {
giveFeedback("Hyperlink clicked!");
var myURL:String = "http://blog.circlecube.com";
var myRequest:URLRequest = new URLRequest(myURL);
try {
navigateToURL(myRequest);
}
catch (e:Error) {
// handle error here
giveFeedback(e);
}
}
//another function to be called from html text, recieves one argument
function moveUp():void {
feedback.y -= 10;
giveFeedback("Up");
}
//a simple trick to allow passing of multiple arguments
function moveDown():void {
feedback.y += 10;
giveFeedback("Down");
}
function giveFeedback(str):void {
trace(str);
feedback.appendText(str +"\n");
feedback.scrollV = feedback.maxScrollV;
}
Source
Download the fla here: textlinkevent_as3.fla