Go Back   kirupaForum > Flash > Flash CS3

Reply
 
Thread Tools Display Modes
Old 08-28-2008, 06:53 AM   #1
kipty
Registered User
Location Sheffield, UK

Posts 39
Line breaks ignored when using HTML text CSS and embedded fonts

FIXED - A Hack but fixed
I'm having some odd behaviour using HTML text, CSS and embedded fonts

see:
http://www.adobe.com/cfusion/webforu...readid=1386999

Am I doing something wrong?

Any help, ideas much appreciated.

Last edited by kipty; 09-04-2008 at 08:26 AM..
kipty is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 08-28-2008, 05:04 PM   #2
iasseo
Registered User
I'm having the same exact problem...

Quote:
Originally Posted by kipty View Post
I'm having some odd behaviour using HTML text, CSS and embedded fonts

see:
http://www.adobe.com/cfusion/webforu...readid=1386999

Am I doing something wrong?

Any help, ideas much appreciated.
iasseo is offline   Reply With Quote
Old 09-04-2008, 08:16 AM   #3
kipty
Registered User
Location Sheffield, UK

Posts 39
OK,
I have given up messing with stylesheets, trying display: block, inline, different ways of formatting the XML, messing with XML.ignoreWhiteSpace, and XML.prettyPrinting etc.

I went down the route of encodeURI, using a RegExp to strip out all tabs, linefeeds and carriage returns. This now gives consistent results for all situations, even embedded and none embedded fonts.

e.g.
_text:String = TEXT FROM XML, HTML TEXT etc

var st:String = encodeURI(_text);

var pattern:RegExp = /(%09)+|(%0A)+|(%0D)+/g;

st = st.replace(pattern, "");
st = decodeURI(st);

YOUTEXTFIELD.htmlText = st;


The <p> tags still behave as a <br/> tag, but you can add an extra <br/> to simulate a paragraph.

Here is the example again with the updates,

HTML Code:
package 
{
 
 import flash.text.Font;
 import flash.text.TextField;
 import flash.text.AntiAliasType;
 import flash.display.MovieClip;
 import flash.text.StyleSheet;
 
 
 public class test extends MovieClip
 {
 
  public function test()
  {
   //get font
   var arial:Font = new _Arial();
   
   //get textfield from stage
   var _IDE_TextField:TextField = TextField(getChildByName("ideTextField"));
   
   //text string
   var _text:String; 
   
   //setup stylesheet
   var _styles:StyleSheet = new StyleSheet();
   var p_StyleObj:Object = new Object();
   p_StyleObj.fontSize = "12";
   p_StyleObj.color = "#000000";
   p_StyleObj.fontFamily = arial.fontName;
   
   _styles.setStyle("p", p_StyleObj);
   
   var alink_StyleObj:Object = new Object();
   alink_StyleObj.color = "#7CCCBF";
   alink_StyleObj.fontWeight = "bold";
   alink_StyleObj.textDecoration = "underline";
   //
   _styles.setStyle("a:link", alink_StyleObj);
   
   var ahover_StyleObj:Object = new Object();
   ahover_StyleObj.color = "#7CCCBF";
   ahover_StyleObj.fontWeight = "bold";
   ahover_StyleObj.textDecoration = "none";
   //
   _styles.setStyle("a:hover", ahover_StyleObj);
   
   var aactive_StyleObj:Object = new Object();
   aactive_StyleObj.color = "#7CCCBF";
   aactive_StyleObj.fontWeight = "bold";
   aactive_StyleObj.textDecoration = "none";
   //
   _styles.setStyle("a:active", aactive_StyleObj);
   
   //dynamic textfield
   var tf:TextField = new TextField();
   tf.styleSheet = _styles;
   
   tf.width = 500;
   tf.height = 200;
   tf.border = true;
   tf.embedFonts = true;
   tf.antiAliasType = AntiAliasType.ADVANCED;
   tf.selectable = true;
   tf.multiline = true;
   tf.wordWrap = true;
   tf.condenseWhite = false;
   
   
   //ide textfield
   _IDE_TextField.styleSheet = _styles;
   
   _IDE_TextField.width = 500;
   _IDE_TextField.height = 200;
   _IDE_TextField.border = true;
   _IDE_TextField.embedFonts = true;
   _IDE_TextField.antiAliasType = AntiAliasType.ADVANCED;
   _IDE_TextField.selectable = true;
   _IDE_TextField.multiline = true;
   _IDE_TextField.wordWrap = true;
   _IDE_TextField.condenseWhite = false;
   //
    
   
   XML.ignoreWhitespace = false; //required as remove spaces between html tags
   XML.prettyPrinting = false;
   
   var textXml_doesnt_work:XML = 
    <text>
     <p>first paragraph <a href="www.google.com">text</a> here</p>
     <p>second paragraph text here</p>
     <p>third paragraph text here</p>
    </text>;
    
   var textXml_othertags_ignored:XML = 
    <text>
     <p>first paragraph <a href="www.google.com">text</a> here</p>
     <br/><br/><br/><b></b><font></font><br></br>
     <p>second paragraph text here</p>
     <p>third paragraph text here</p>
    </text>;
    
   var textXml_works_forAS_textfield:XML = 
    <text>
     <p>first paragraph <a href="www.google.com">text</a> here</p><p/><p>second paragraph text here</p><p>third paragraph text here</p>
    </text>;
    
   var textXml_works_forIDE_Textfield:XML = 
    <text><p>first paragraph <a href="www.google.com">text</a> here</p><p>second paragraph text here</p><p>third paragraph text here</p></text>;
    
   var textXml_works_but_with_extra_paragrahs:XML = 
    <text>
     <p>first paragraph <a href="www.google.com">text</a> here</p>
     <p/>
     <p>second paragraph text here</p>
     <p>third paragraph text here</p>
    </text>;
    
   //grab the html from inside the <text> tags
   
   _text = textXml_doesnt_work.children().toString();
   //_text = textXml_othertags_ignored.children().toString();
   //_text = textXml_works_forAS_textfield.children().toString();
   //_text = textXml_works_forIDE_Textfield.children().toString();
   //_text = textXml_works_but_with_extra_paragrahs.children().toString();
   
   
   var st:String = encodeURI(_text);
   var pattern:RegExp = /(%09)+|(%0A)+|(%0D)+/g; 
   
   st = st.replace(pattern, "");
   //trace(st)
   st = decodeURI(st);
   
   _IDE_TextField.htmlText = st;
   
   tf.htmlText = st;
   
   addChild(tf);
  }
 }
}
Hope this helps someone

Last edited by kipty; 09-04-2008 at 08:23 AM..
kipty is offline   Reply With Quote
Old 09-17-2008, 08:47 PM   #4
Pherank
Registered User
Location California

Posts 476
I get errors in strict mode using the code below. It would be great if someone could post the working "test.as" page.
Pherank is offline   Reply With Quote
Old 09-18-2008, 12:17 PM   #5
kipty
Registered User
Location Sheffield, UK

Posts 39
Here is a zip with the files in, hope it helps
Attached Files
File Type: zip test.zip (28.3 KB, 134 views)
kipty is offline   Reply With Quote
Old 10-04-2008, 04:06 PM   #6
troyfoley
Registered User
@kipty
That's awesome. Thanks a bunch, man.
troyfoley is offline   Reply With Quote
Reply

Tags
as3, css, embedded fonts, html text


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:19 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com