A class written in as2 to dynamically load CSS styles

Source: Internet
Author: User
I used to read an article about ultrashock. Article , So I wrote a class, which makes it much easier to use.

/*************************************** * ** Cssstyle * References an external style sheet to the component * eg: * var cssstyle: cssstyle = new cssstyle ("style.css"); * apply the style to _ root. mycombox object * cssstyle. applyto (_ root. mycombox, "combox"); * apply the style to all ComboBox objects * cssstyle. applyto (_ global. styles. comboBox, "combox"); * apply the style to all components * cssstyle. applyto (_ global. style, "combox "); * *****************************/class cssstyle {// style table path Private VaR Csspath: String ; Private VaR Isloaded: Boolean = False ; Private VaR Cssresult; Public Function Cssstyle (_ csspath:String ){ This . Csspath = _ csspath; This . Incircle ();} // applyto method // _ component: component or Mc object to apply the style // _ style: style name of the application Public Function Applyto (_ component: Object , _ Style: String ): Void { VaR Component: Object = _ Component; VaR Style: String = _ Style; VaR SELF: Object = This ; If (Self.css result = Undefined ){ VaR Cssdata: Loadvars = New Loadvars (); Cssdata. Load ( This . Csspath); cssdata. ondata = Function (Raw) {self.css result = New Textfield . Stylesheet (); self.css result. parsecss (raw); self. applycss (component, self.css result. _ CSS [style]);} Else {Self. applycss (component, self.css result. _ CSS [style]) ;}// apply the style sheet content to the specified component. Private Function Applytocomponent (targetobj: Object , Styleobj: Object ){ For ( VaR I In Styleobj ){ If (Styleobj [I]. substr (0, 1) = "#") {styleobj [I] = "0x" + styleobj [I]. substr (1);} targetobj. setstyle (I, styleobj [I]) ;}// pass the style sheet component and object to the application function Private Function Applycss (COMP, cssobj) {applytocomponent (COMP, cssobj);} // Initialization Private Function Inode (): void { VaR SELF: Object = This ; VaR Cssdata: Loadvars = New Loadvars (); Cssdata. Load ( This . Csspath); cssdata. ondata = Function (Raw) {self.css result = New Textfield . Stylesheet (); self.css result. parsecss (raw );};}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.