| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
E-learning Developer
Join Date: Sep 2006
Posts: 95
|
Greetings;
I have tried to get this to work in AS3, but no go so far. I use the below to call a function. My AS2 code is: mytxt[1] = "<a href=\'asfunction:myfunc_1\'><b>My Text</b></a>"; I know that asfunction is no longer used and I tried to use this: mytxt[1] = "<a href=\'event:myfunc_1\'><b>My text</b></a>" as you can guess, it does not work. Any help will be greatly appreciated. |
|
|
|
|
|
#2 |
|
E-learning Developer
Join Date: Sep 2006
Posts: 95
|
Got this and it works:
var linkText:TextField = new TextField(); linkText.htmlText = 'Link: <a href="event:Link Clicked">Click</a>'; addChild(linkText); linkText.addEventListener(TextEvent.LINK, linkEvent); function linkEvent(event:TextEvent):void { trace(event.text); // Link Clicked } Now the questions is, how can I have multiple links within a text field? I have multiple asfunction calls within text fields so users can access informatin. All my attempts to do this with the above have failed. If I have two calls and two listeners, each link calls both functions. TIA |
|
|
|
|
|
|
|
|
#3 |
|
Marketer/Technologist
Join Date: Sep 2007
Location: San Diego, CA
Posts: 434
|
You only add one listener - you call the appropriate function based on what event.text says - that's supposed to reflect the function name and its args.
|
|
|
|
|
|
#4 |
|
E-learning Developer
Join Date: Sep 2006
Posts: 95
|
Thank you Sekhar,
Below is my implementation based on your help. Now I can finish the recoding of my projects with this function. Cheers! var mytxt:Array = new Array; mytxt[0] = "<a href=\'event:myfunc\'><b>My text</b></a>, <a href=\'event:myfunc1\'><b>My text 1</b></a>, <a href=\'event:myfunc2\'><b>My text 2</b></a>"; tf.htmlText= mytxt[0]; tf.addEventListener(TextEvent.LINK, linkEvent); function linkEvent(event:TextEvent):void { switch (true) { case (event.text == "myfunc") : box_mc.x = 200.0; break; case (event.text == "myfunc1") : box_mc.x = 10.0; break; case (event.text == "myfunc2") : box_mc.x = 150.0; break; default : trace("curious"); } } Last edited by desighforce; 06-02-2008 at 11:58 PM.. Reason: typo |
|
|
|
|
|
#5 |
|
Site Contributor
Join Date: Jun 2008
Location: Brooklyn
Posts: 360
|
glad your problem is solved but wanted to point out you kind of have an odd way to use a switch statement.
the point of a switch is to make a long if-else block look a bit more elegant when you have just one value to switch on. It will automatically do the == comparison for you for whatever you write after "case" and before ":" so instead of: ActionScript Code:
try this: ActionScript Code:
|
|
|
|
|
|
#6 |
|
E-learning Developer
Join Date: Sep 2006
Posts: 95
|
Thank you pj-co,
I took your advice and it has made my life a little easier. Cheers! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help convert from AS2 to AS3 | Pixrite | ActionScript 3.0 | 3 | 05-08-2008 04:56 PM |
| how do I convert this AS2 to AS3 | Tillthen | ActionScript 3.0 | 2 | 02-13-2008 01:44 PM |
| Convert Short Code To AS3 | jeff_way | ActionScript 3.0 | 0 | 01-13-2008 04:20 PM |
| help me convert this to AS3 | malx | ActionScript 3.0 | 6 | 01-03-2008 04:21 PM |
| applying actions to dynamic text. | exactpixel | Simple Stuff (Newbies) | 15 | 05-04-2003 06:20 PM |