0

I'm trying to insert a list of textField object into a movie clip and make them clickable. The textfields come from an array of variable elements, and I draw the text on the movie clip but then I'm unable to find a way to make them clickable individually. I've found the following code on internet:

this.createEmptyMovieClip("txt_mc", this.getNextHighestDepth());
var txt:TextField = txt_mc.createTextField("tContinue", 0, 195, 138, 200, 40);
txt.multiline = txt.border = txt.wordWrap = true;
txt.text = "Click here to execute the function.";
txt_mc.createEmptyMovieClip("invisible", 1);
with (txt_mc.invisible) {
    beginFill(0x000000, 0);
    moveTo(195, 138);
    lineTo(395, 138);
    lineTo(395, 178);
    lineTo(195, 178);
    lineTo(195, 138);
    endFill();
}

txt_mc.onRelease = function() {
    trace("Hello!");
    //-->> How can I know which element has been clicked??
}

The code above works fine, but it's completely useless to my purpose as I need to know which textfield has been clicked by the user (I've several textfields) to read its text and pass to another function.

Is there any way to do so in Actionscript 2?

1 Answer 1

0

I've found the solution:

var lbl = planMC.textObject.createTextField("txtRoomCode", tn, xt - minPlanX, yt - minPlanY, 150, 90);
lbl.html = true;
lbl.htmlText = "<a href='asfunction:linkHandler," + parameters + "'>" + lblText + "</a>";
lbl.textColor = 0xFF0000;
lbl.setTextFormat(textFormat);
lbl._parent.linkHandler = Delegate.create(this, linkHandler); 

and here the called function:

linkHandler = function (param:String)
{
   trace(param);
};

Remeber to import import mx.utils.Delegate;

the problem is that this solution works only for text and not for images or vectorial shapes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.