Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
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.

813 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

10 Experts available now in Live!

Get 1:1 Help Now