Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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
need a player that can play .d and .i DVR files 9 1,592
Youtube video error 30 841
Failed download 57 581
2012 Domain With 350 Machines All Running Windows 7 7 139
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 …
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. …
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

733 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