Solved

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

Posted on 2008-10-19
2
684 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

717 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