04Mar
[AS 3] Text Links calling Actionscript Functions
No commentsIn this demo I have utilized the Button and the Yahoo! AlertManager component. I simply created a textfield in the upper left corner with an html anchor tag that calls a function within the Actionscript code.
Here is my Document Class file TextHTMLLinks.as:
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.events.TextEvent;
import com.yahoo.astra.fl.managers.AlertManager;
import fl.events.ComponentEvent;
import flash.events.MouseEvent;
public class TextHTMLLinks extends Sprite
{
private var myFormat:TextFormat;
private var myTextField:TextField;
public function TextHTMLLinks():void
{
// format the text
var myFormat:TextFormat = new TextFormat();
myFormat.size = 16;
myFormat.font = "Arial";
myFormat.color = 0xffffff;
// create the text field and add the link
var myTextField:TextField = new TextField();
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.multiline = true;
myTextField.defaultTextFormat = myFormat;
myTextField.htmlText = "
Here is my title
";
myTextField.htmlText += "
Click here for the alert box
";
// add the listener for the link
myTextField.addEventListener(TextEvent.LINK, clickLink);
// add the object to the stage
addChild(myTextField);
}
private function clickLink(e:TextEvent):void
{
if (e.text == "alert")
{
AlertManager.createAlert(this, "Here is my message", "My Title: Alert Box",["close alert"]);
}
}
}
}
Categories: Actionscript 3, Flash Text / HTML / CSS
Tuesday, March 4th, 2008 at 5:38 am and is filed under Actionscript 3, Flash Text / HTML / CSS. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.