help with asfunction

  • Flanders
  • Beginner
  • Beginner
  • User avatar
  • Posts: 48
  • Loc: Reno, Nevada US

Post 3+ Months Ago

I am stuck on something with a site I am working on. I have used this in the past with a set number of functions, but I am at a loss here.

Lets say I have 3 lines of text in a dynamic text field that are tied to asfunction. In other words, line 1 clicked on will run function1(), line 2 clicked will run function2() and so on. This works fine, but if the number of lines is variable, how would I do this? Each line of text is generated by PHP from mySQL and read into the textfield from AS. I need to be able to pass the parameter to the actionscript function depending on which line is clicked. i.e. line 1 clicked runs asfunction:function, 1. line 2 clicked runs asfunction:function, 2, etc. I'm not sure if this is clear, but any insight would save my butt.

  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

ye, got your point. But is there such thing as detecting which line was clicked?
If so, please enlight me.
From my point of view, create a base movie clip in the library, which contains a dynamic text field. Then, for each line that u want to display, attach the movie clip from the library and define the onPress method for it.
Code: [ Select ]
this.createEmptyMovieClip("lines", 0);

for (i=0; i<linesCount; i++)
   crtLine = lines.attachMovie("line", "line"+i, i);
   crtLine.onPress = function()
   { switch (i)
       case 0: function1(); break;
       case 1: function2(); break;
       case 2: function3(); break;
  1. this.createEmptyMovieClip("lines", 0);
  2. for (i=0; i<linesCount; i++)
  3. {
  4.    crtLine = lines.attachMovie("line", "line"+i, i);
  5.    crtLine.onPress = function()
  6.    { switch (i)
  7.      { 
  8.        case 0: function1(); break;
  9.        case 1: function2(); break;
  10.        case 2: function3(); break;
  11.        .......
  12.      }
  13.    }  
  14. }

another thing u can do, create a movieClip and for each for each function you want to call, create a key frame where u have the name of the function
and then call it, then stop.
i.e.: frame 5:
Code: [ Select ]
function f5() { ... };
  1. function f5() { ... };
  2. f5();
  3. stop();

and in the
onPress function:
  • Flanders
  • Beginner
  • Beginner
  • User avatar
  • Posts: 48
  • Loc: Reno, Nevada US

Post 3+ Months Ago

I actually figured out the answer to my own question (again). I think it helps to post here, though. Kinda jars my brains into gear. What I did was:

when writing out the <a href> tag, I just used the i from the for loop as the parameter being passed to the function.

textField.htmlText +="<a href=\"asfunction:functionName,"+i+"\">Click here!</a>";

function functionName(number){

this returns 0, 1, 2 or whichever line you clicked on that was generated by the for loop. Works like a champ!

This forum rocks! Thanks for all the help I've gotten here.


Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 15 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.