Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-02-2008, 02:25 AM   #1
desighforce
E-learning Developer
 
Join Date: Sep 2006
Posts: 88
Default Asfunction - Convert To As3 Assistance

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.
desighforce is offline   Reply With Quote
Old 06-02-2008, 03:03 AM   #2
desighforce
E-learning Developer
 
Join Date: Sep 2006
Posts: 88
Default Partially solved

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
desighforce is offline   Reply With Quote
Old 06-02-2008, 03:08 AM   #3
Sekhar
Marketer/Technologist
 
Join Date: Sep 2007
Location: San Diego, CA
Posts: 434
Default

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.
Sekhar is offline   Reply With Quote
Old 06-02-2008, 11:54 PM   #4
desighforce
E-learning Developer
 
Join Date: Sep 2006
Posts: 88
Default Resolved!

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
desighforce is offline   Reply With Quote
Old 06-03-2008, 05:12 AM   #5
pj-co
Site Contributor
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 311
Cool

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:
switch(true) {      case (something == something): }

try this:

ActionScript Code:
function linkEvent( txtEvt :TextEvent ) :void {      switch ( txtEvt.text )      {           case "myfunc" :           box_mc.x = 200.0;           break;           case "myfunc1" :           box_mc.x = 10.0;           break;           case "myfunc2" :           box_mc.x = 150.0;           break;           default :           trace("function not found");      } }
pj-co is offline   Reply With Quote
Old 06-03-2008, 02:04 PM   #6
desighforce
E-learning Developer
 
Join Date: Sep 2006
Posts: 88
Thumbs up Thanks!

Thank you pj-co,

I took your advice and it has made my life a little easier.

Cheers!
desighforce is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT. The time now is 05:32 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.