Solved

AS3: Can you apply a style sheet to a textfiled in a movieclip?

Posted on 2008-10-19
2
661 Views
Last Modified: 2013-11-11
I just asked a very similar question, but I'm trying now to attack the problem from a different view point. If I have a movieclip with text fields and I attach that movie to the stage - can I then add a style sheet format to the text field before adding the text? All the examples I've seen of how to use stylesheets in as3 start with creating the text field in the AS code. I want to apply my stylesheet info to a text field that is already created on the stage.
0
Comment
Question by:katyjack
  • 2
2 Comments
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 22752566
yes, here is the code to implement inline StyleSheet:


import flash.text.StyleSheet;

var myCSS = new StyleSheet();
var aHover:Object = new Object();
aHover.fontWeight = "bold";
aHover.textDecoration = "underline";
myCSS.setStyle("a:hover",aHover);
var aLink:Object = new Object();
aLink.fontWeight = "normal";
aLink.textDecoration = "none";
myCSS.setStyle("a:link",aLink);

// Assume TextField instance nameis myTxt;

myTxt.styleSheet = myCSS;
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 22752575
you can also load an external .css file and implement it on flash textFields..

"style.css" contents:

a:link {
      color: #FF6600;
      text-decoration: none;
}
a:hover {
      color: #FF6600;
      text-decoration: underline;
}


actionscript code to load the CSS file in flash...

                  import flash.external.*;
                  import flash.display.*;
                  import flash.events.*;
                  import flash.utils.*;
                  import flash.net.*;
                  import flash.text.StyleSheet;

                  var myCSS = new StyleSheet();
                  
                  var loader:URLLoader = new URLLoader();
                  loader.load(new URLRequest("style.css"));

                  loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
                  loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);

                  function errorHandler(e:IOErrorEvent):void {
                        trace("Couldn't load the style sheet file.");
                  }

                  function loaderCompleteHandler(event:Event):void {
                        myCSS.parseCSS(loader.data);
                  }


// Assume TextField instance nameis myTxt;
myTxt.styleSheet = myCSS;
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to how to record live broadcast.
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now