Use external CSS to set the appearance of Flash MX 2004 components

xiaoxiao2021-03-06  110

While Working On A Project At Schematic, I Was Investigating The Possibility of Defining Style Attributes for Component Instances in An External CSS File. I Got The Following System To Work:

1. Create An External CSS File, Defining The Style (s) And Component-Specific Styles You Want To Customize. For Example:

/ * Filename: Styles.css * / Checkbox {color: 0x0000FF; Embedfonts: false; fontfamily: arial; fontsize: 24;

2. Load The Style Sheet INTO YOUR FLASH MOVIE, RETRIEVE The Style Name, And Apply It to your instance:

import mx.controls.CheckBox; var oStyle: Object; var ccbTest: mx.controls.CheckBox; var styles = new TextField.StyleSheet (); styles.onLoad = function (bSuccess: Boolean): Void {if (bSucess) {oStyle = this.getStyle ("CheckBox"); for (VAR I in ostyle) {ccbtest.setStyle (I, OSTYLE [I]);}}}}} else {trace ("Error Loading CSS File);}}; LOAD ("styles.css");

--From (http://blogs.flashsupport.com/robert/archive/2004/09/08/209.aspx)

- Translation Edition

Editor's Note: We all know that you can easily set the appearance of the Flash MX 2004 component, but if you can use an external CSS file to control, it is not better, it will be more convenient to use. Here is an example discovered online (original website: http://blogs.flashsupport.com/robert/archive/2004/09/08/209.aspx):

1. Create a CSS file to define some properties of the component, such as: / * filename: style.css * /

Checkbox {

COLOR: 0x0000FF;

Embedfonts: false;

Fontfamily: arial;

FONTSIZE: 24;

}

2. Load this CSS file in Flash, put the component set on the component:

Import mx.controls.checkbox;

Var ostyle: Object;

VAR CCBTEST: MX.CONTROLS.CHECKBOX;

Var styles = new textfield.stylesheet ();

Styles.onLoad = Function (BSUCCESS: BOOLEAN): void {

IF (bsucess) {

Ostyle = this.getStyle ("Checkbox");

For (Var i in ostyle) {

CCBTest.setStyle (i, OSTYLE [I]);

}

Else {Trace ("Error Loading CSS File.");

}

}

Styles.Load ("styles.css");

转载请注明原文地址:https://www.9cbs.com/read-102610.html

New Post(0)