LogoLogo
  • Home
  • Projects
  • About
  • Contact

Event.EXIT_FRAME && Multi Column Text in Flash 10

Devon O. · May 25, 2008 · Actionscript · 4 comments
3

All right, I’ll be the first in class to raise my hand and ask a potentially stupid question: What the hell is Event.EXIT_FRAME for? Playing around with it, it seems to do the same thing as Event.ENTER_FRAME. In fact, contrary to what I was expecting, it seems to fire before the ENTER_FRAME event. Most peculiar, mama. Of course, it’s entirely possible that .swf applications begin by leaving a frame rather than entering one. Not really something I’d ever considered before. In any case, if anyone wants to shed some light on the purpose of this odd event, I’d be most obliged.

In the meantime, while I’ve seen plenty of examples of 3d and sound generation, I haven’t seen much on the new text engine in the Flash 10 player, so I threw together my own example. There may be an easier way to do this, but this is new territory, man. Besides, this isn’t that complicated considering it generates dynamic multi-columned text. And just look at that purty antialiased system font.

The class in question:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package {
 
    import com.onebyonedesign.ui.events.ComboBoxEvent;
    import com.onebyonedesign.ui.OBO_ComboBox;
    import flash.display.Sprite;
    import flash.text.engine.ContentElement;
    import flash.text.engine.TextJustifier;
    import flash.text.engine.LineJustification;
    import flash.text.engine.TextBlock;
    import flash.text.engine.TextElement;
    import flash.text.engine.GroupElement;
    import flash.text.engine.TextLine;
    import flash.text.engine.ElementFormat;
    import flash.text.engine.FontDescription;
 
    [SWF(width="500", height="500", backgroundColor="#FFFFFF", framerate="31")]
    public class MultiColumnTextExample extends Sprite {
 
        private var _numLines:int = 20;
        private var _lineWidth:int = 150;
        private var _linesCB:OBO_ComboBox;
        private var _widthCB:OBO_ComboBox;
 
        private var _textBlock:TextBlock;
        private var _textLines:Vector.<TextLine>;
 
        private var _textHolder:Sprite = new Sprite();
 
        public function MultiColumnTextExample():void {
 
            var format:ElementFormat = new ElementFormat();
            var fontDescription:FontDescription = new FontDescription("Arial");
            format.fontSize = 11;
            format.fontDescription = fontDescription;
 
            var testString:String = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas at leo eget nisl porta viverra. Ut laoreet, dui at tempus vestibulum, eros leo egestas neque, id adipiscing odio eros et lectus. Vivamus pretium lorem sit amet nulla. Praesent nec dolor at augue ultrices blandit. Quisque aliquet ultrices mi. Donec ac nibh. Phasellus sed sem sed mauris mattis laoreet. Ut fermentum augue ac pede. Duis vitae augue sed nulla lacinia tempor. Pellentesque non ante in magna tincidunt malesuada. Nunc eu mi. Nulla adipiscing posuere nunc. Donec congue, sem vitae aliquam sagittis, tellus lectus laoreet libero, in interdum mi dui ut tellus. Nam pulvinar nibh a ante. Maecenas laoreet placerat ante. Vivamus feugiat magna ut leo. Integer sed risus. Quisque porttitor massa a sem. Sed mollis, purus vel condimentum tristique, enim wisi gravida erat, at hendrerit libero neque sit amet felis. Duis quis erat sed est vestibulum viverra. Sed eu wisi. Praesent nunc. Pellentesque porttitor, augue quis commodo accumsan, purus lorem ullamcorper eros, eu mollis wisi sapien vel lectus. Vivamus metus wisi, sollicitudin a, bibendum quis, dictum ut, lectus. In hac habitasse platea dictumst. Cras eget purus. Vestibulum turpis. Sed ultricies, neque id cursus pretium, nibh tellus eleifend metus, sit amet tempus augue magna at dolor. Proin eleifend. Sed laoreet pharetra quam. Sed gravida pharetra eros. Praesent feugiat. Vestibulum in ligula. Sed in tellus sed lorem pretium accumsan. Vivamus fringilla, neque ac venenatis varius, orci pede lobortis est, quis volutpat arcu leo vel mauris. Curabitur imperdiet nunc nec nunc.";
 
            var textElement:TextElement = new TextElement(testString, format);
            var groupVector:Vector.<ContentElement> = new Vector.<ContentElement>();
            groupVector.push(textElement);
            var groupElement:GroupElement = new GroupElement(groupVector);
 
            _textBlock = new TextBlock();
            _textBlock.content = groupElement;
            createTextLines();
 
            _linesCB = new OBO_ComboBox("Number of lines per column:", _numLines.toString(), [ { label:"20", data:20 }, { label:"25", data:25 }, { label:"30", data:30 }, { label:"35", data:35 } ], 40);
            _linesCB.addEventListener(ComboBoxEvent.OPTION_SELECTED, comboHandler);
            _linesCB.x = 20;
            _linesCB.y = 470;
            addChild(_linesCB);
 
            _widthCB = new OBO_ComboBox("Number of characters per column:", _lineWidth.toString(), [ { label:"100", data:100 }, { label:"150", data:150 }, { label:"200", data:200 } ], 40);
            _widthCB.addEventListener(ComboBoxEvent.OPTION_SELECTED, comboHandler);
            _widthCB.x = _linesCB.x + _linesCB.width + 20;
            _widthCB.y = 470;
            addChild(_widthCB);
 
            addChild(_textHolder);
        }
 
        private function comboHandler(event:ComboBoxEvent):void {
            clearTextLines();
            if (event.currentTarget == _linesCB) {
                _numLines = event.data;
            } else {
                _lineWidth = event.data;
            }
            createTextLines();
        }
 
        private function clearTextLines():void {
            // release previous lines for potential garbage collection
            _textBlock.releaseLines(_textBlock.firstLine, _textBlock.lastLine);
 
            // remove the previous lines from the text holding sprite
            var len:int = _textLines.length;
            for (var i:int = 0; i < len; i++)
                _textHolder.removeChild(_textLines[i]);
        }
 
        private function createTextLines():void {
 
            var xPos:int = 0;
            var yPos:int = 0;
            var textLine:TextLine = _textBlock.createTextLine(null, _lineWidth);
            var currentLine:int = 1;
 
            // rewrite the _textLines vector
            _textLines = new Vector.<TextLine>();
 
            while (textLine) {
                _textHolder.addChild(textLine);
                _textLines.push(textLine);
                textLine.x = xPos;
                yPos += textLine.textHeight + 3;
                textLine.y = yPos;
                textLine = _textBlock.createTextLine(textLine, _lineWidth);
                if (currentLine++ % _numLines == 0) {
                    xPos += _lineWidth + 5;
                    yPos = 0;
                }
            }
        }
    }
}

and the example (which, again, requires the Flash 10 player to be installed):

  Facebook   Pinterest   Twitter   Google+
  • JiblibFlash + Augmented Reality (Take Three)
    May 26, 2009 · 13 comments
    3906
    2
    Read more
  • Pratique d’ActionScript 3
    April 28, 2008 · 0 comments
    1358
    4
    Read more
  • Lorenz Attractor – HTML5 Stylee
    February 06, 2010 · 1 comments
    2547
    4
    Read more
4 Comments:
  1. What about superscript and subscript in dynamic text fields (without using a custom font)?

    Are we there yet?

    Are we there yet?

    Are we there yet…?

    Dave · May 26, 2008
  2. Absolutely…

    package {

    import flash.display.Sprite;
    import flash.text.engine.ContentElement;
    import flash.text.engine.TextBlock;
    import flash.text.engine.TextElement;
    import flash.text.engine.GroupElement;
    import flash.text.engine.TextLine;
    import flash.text.engine.ElementFormat;
    import flash.text.engine.FontDescription;
    import flash.text.engine.TextBaseline;

    [SWF(width=”500″, height=”50″, backgroundColor=”#FFFFFF”, framerate=”31″)]
    public class SubSuperscriptTextExample extends Sprite {

    public function SubSuperscriptTextExample():void {

    var regularFormat:ElementFormat = new ElementFormat();
    var fontDescription:FontDescription = new FontDescription(“Arial”);
    regularFormat.fontSize = 12;
    regularFormat.fontDescription = fontDescription;

    var subFormat:ElementFormat = new ElementFormat();
    subFormat.fontSize = 9;
    subFormat.fontDescription = fontDescription;
    subFormat.alignmentBaseline = TextBaseline.SUBSCRIPT;

    var superFormat:ElementFormat = new ElementFormat();
    superFormat.fontSize = 9;
    superFormat.fontDescription = fontDescription;
    superFormat.alignmentBaseline = TextBaseline.SUPERSCRIPT;

    var testString1:String = “This is some regular text. And this “;
    var superString:String = “is some superscript. “;
    var testString2:String = “And this here “;
    var subString:String = “is some subscript.”;

    var textElement1:TextElement = new TextElement(testString1, regularFormat);
    var textElement2:TextElement = new TextElement(superString, superFormat);
    var textElement3:TextElement = new TextElement(testString2, regularFormat);
    var textElement4:TextElement = new TextElement(subString, subFormat);

    var groupVector:Vector. = new Vector.();

    groupVector.push(textElement1, textElement2, textElement3, textElement4);
    var groupElement:GroupElement = new GroupElement(groupVector);

    var textBlock:TextBlock = new TextBlock();
    textBlock.content = groupElement;
    var textLine:TextLine = textBlock.createTextLine();
    textLine.x = 20;
    textLine.y = 30;
    addChild(textLine);
    }
    }
    }

    Devon O. · May 26, 2008
  3. Whoa thats insane.
    Thanks for sharing.

    Acts7 · May 27, 2008

Sorry, the comment form is closed at this time.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • MainDepth on Unity Ripple or Shock Wave Effect
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2021 Devon O. Wolfgang