Solved

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

Posted on 2008-10-19
2
674 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Embedded Video Download (Flash) 3 1,161
Begin mp4 video on first frame 6 178
Windows 7, Adobe Flash Player and Internet Explorer 11 15 103
Can't play streaming video on event.on24.com 7 343
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

809 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