Notes
Notes: CSS StyleSheets
Note: A text field with a style sheet is not editable. In other words, a text field with the type property set to TextFieldType.INPUT applies the StyleSheet to the default text for the text field, but the content will no longer be editable by the user. Consider using the TextFormat class to assign styles to input text fields.
Flash Player supports a subset of properties in the original CSS1 specification (www.w3.org/TR/REC-CSS1). The following table shows the supported Cascading Style Sheet (CSS) properties and values, as well as their corresponding ActionScript property names. (Each ActionScript property name is derived from the corresponding CSS property name; if the name contains a hyphen, the hyphen is omitted and the subsequent character is capitalized.)
Notes: HTMLText
This is the first of hopefully a series of posts of useful things I want accessible on my blog. Mostly for my own benefit but anyone else is free to use this as an easy reference for AS3.
Flash Player supports the following HTML tags:
Anchor tag
The <a> tag creates a hypertext link and supports the following attributes:
target: Specifies the name of the target window where you load the page. Options include_self,_blank,_parent, and_top. The_selfoption specifies the current frame in the current window,_blankspecifies a new window,_parentspecifies the parent of the current frame, and_topspecifies the top-level frame in the current window.href: Specifies a URL or an ActionScriptlinkevent.The URL can be either absolute or relative to the location of the SWF file that is loading the page. An example of an absolute reference to a URL ishttp://www.adobe.com; an example of a relative reference is/index.html. Absolute URLs must be prefixed with http://; otherwise, Flash treats them as relative URLs.You can use the
linkevent to cause the link to execute an ActionScript function in a SWF file instead of opening a URL. To specify alinkevent, use the event scheme instead of the http scheme in yourhrefattribute. An example ishref="event:myText"instead ofhref="http://myURL"; when the user clicks a hypertext link that contains the event scheme, the text field dispatches alinkTextEvent with itstextproperty set to “myText“. You can then create an ActionScript function that executes whenever the link TextEvent is dispatched. You can also definea:link,a:hover, anda:activestyles for anchor tags by using style sheets.
var style:StyleSheet = new StyleSheet();
var link:Object = new Object();
link.fontWeight = "bold";
link.color = "#FF0000";
var hover:Object = new Object();
hover.fontStyle = "italic";
var active:Object = new Object();
active.fontStyle = "italic";
active.color = "#FFFF00";
style.setStyle("a:link", link);
style.setStyle("a:hover", hover);
style.setStyle("a:active", active);
var txt:TextField = new TextField();
txt.width = 400;
txt.styleSheet = style;
txt.htmlText = "Visit: <a href='www.google.com' target='_blank'>Google.com</a> or call a <a href='event:link1'>function</a>";
txt.addEventListener(TextEvent.LINK, linkHandler);
addChild(txt);
function linkHandler(event:TextEvent):void {
if(event.text == "link1") {
trace("hello!");
}
}