notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : mtok's Draw Grid [diff(69)]

embed

FAVORITE BY
:
FP10TextLayout
:
text縦書き
:
双方向リストのクラスが良さげ
:
縦書き!
FORKED
  1. // forked from mtok's Text Engine 縦書きサンプル
  2. package
  3. {
  4.     [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
  5.     import flash.display.Shape;
  6.     import flash.display.Sprite;
  7.     import flash.geom.Rectangle;
  8.     import flash.text.engine.EastAsianJustifier;
  9.     import flash.text.engine.ElementFormat;
  10.     import flash.text.engine.FontDescription;
  11.     import flash.text.engine.TextBlock;
  12.     import flash.text.engine.TextBaseline;
  13.     import flash.text.engine.LineJustification;
  14.     import flash.text.engine.TextElement;
  15.     import flash.text.engine.TextLine;
  16.     import flash.text.engine.TextRotation;
  17.     import flash.system.Capabilities;
  18.     /**
  19.      * ...
  20.      * @author ...
  21.      */
  22.     public class Tategaki extends Sprite
  23.     {
  24.         private var grid:Shape;
  25.         private var screen:Sprite;
  26.         public function Tategaki() 
  27.         {
  28.             grid = new Shape();
  29.             grid.graphics.lineStyle(1, 0xA0EBF3);
  30.             GraphicsUtils.drawGrid(grid.graphics, new Rectangle(00451451), 50);
  31.             GraphicsUtils.drawGrid(grid.graphics, new Rectangle(00451451), 25, Vector.<Number>([2.5,2.5]));
  32.             addChild(grid);
  33.             
  34.             addChild(screen = new Sprite());
  35.             
  36.             grid.x = screen.x = 5;
  37.             grid.y = screen.y = 5;
  38.             
  39.             var japanese:String = "そこから出発して三日のあいだ東の方へ進んでゆくと、ディオミーラにまいります。\n都市には七十の銀の丸屋根、あらゆる神々の銅像、錫を敷きつめた道、玻璃づくりの劇場、朝ごとに塔の上より刻を告げる金の鶏がございます。すべてこのようなめでたさは、旅人ならば他国でも目にしてとっくに知っておるものばかりでございます。";
  40.             
  41.             var textBlock:TextBlock = new TextBlock();
  42.             var font:FontDescription = new FontDescription();
  43.             if (Capabilities.os.search("Mac OS") > -1) { 
  44.                 font.fontName = "MS 明朝";
  45.             } else {
  46.                 font.fontName = "MS 明朝";
  47.             }
  48.             
  49.             var format:ElementFormat = new ElementFormat(font);
  50.             format.fontSize = 28;
  51.             format.locale = "ja";
  52.             format.color = 0x222222;
  53.             textBlock.baselineZero = TextBaseline.IDEOGRAPHIC_CENTER;
  54.             textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_INCLUDING_LAST);
  55.             textBlock.lineRotation = TextRotation.ROTATE_90;
  56.             
  57.             var linePosition:Number = this.stage.stageWidth - 40;
  58.             
  59.             
  60.             textBlock.content = new TextElement(japanese, format);
  61.             
  62.             var previousLine:TextLine = null;
  63.             var textLine:TextLine;
  64.             
  65.             screen.graphics.lineStyle(1, 0xff0000);
  66.             while (true) {
  67.                 textLine = textBlock.createTextLine(previousLine, 450);
  68.                 if (textLine == null)
  69.                     break;
  70.                 textLine.y = 0;
  71.                 textLine.x = linePosition;
  72.                 
  73.                 screen.graphics.moveTo(textLine.x, textLine.y);
  74.                 screen.graphics.lineTo(textLine.x, textLine.height);
  75.                 
  76.                 linePosition -= 50;
  77.                 screen.addChild(textLine);
  78.                 previousLine = textLine;
  79.             }
  80.         }
  81.         
  82.     }
  83. }
  84. import flash.display.Graphics;
  85. import flash.geom.Point;
  86. import flash.geom.Rectangle;
  87. class GraphicsUtils {
  88.     public function GraphicsUtils() {
  89.         ;
  90.     }
  91.     public static function drawGrid(g:Graphics, rect:Rectangle, size:Number, pattern:Vector.<Number> = null):void {
  92.         var i:Number;
  93.         var limitW:Number;
  94.         var limitH:Number;
  95.         
  96.         limitW = rect.x + rect.width;
  97.         limitH = rect.y + rect.height;
  98.         if (pattern == null) {
  99.             i = rect.y;
  100.             while (i < limitH) {
  101.                 g.moveTo(rect.x, i);
  102.                 g.lineTo(limitW, i);
  103.                 i += size;
  104.             }
  105.             i = rect.x;
  106.             while ( i < limitW) {
  107.                 g.moveTo(i, rect.y);
  108.                 g.lineTo(i, limitH);
  109.                 i += size;
  110.             }
  111.         }else {
  112.             i = rect.y;
  113.             while (i < limitH) {
  114.                 drawDotLine(g, rect.x, i, limitW, i, pattern);
  115.                 i += size;
  116.             }
  117.             i = rect.x;
  118.             while (i < limitW) {
  119.                 drawDotLine(g, i, rect.y, i, limitH, pattern);
  120.                 i += size;
  121.             }
  122.         }
  123.     }
  124.     public static function drawDotLine(g:Graphics, fromX:Number, fromY:Number, toX:Number, toY:Number, pattern:Vector.<Number>):void {
  125.         var i:int;
  126.         var n:Number;
  127.         var v:Point = new Point(toX - fromX, toY - fromY);
  128.         var tmp:Point;
  129.         var l:Number = v.length;
  130.         var sl:SimpleList = new SimpleList();
  131.         var s:Boolean = true;
  132.         v.normalize(1);
  133.         
  134.         for (i = 0; i < pattern.length; i++) {
  135.             n = pattern[i];
  136.             tmp = v.clone();
  137.             tmp.normalize(n);
  138.             sl.append({v:tmp, length:n});
  139.         }
  140.         
  141.         
  142.         var pos:Point = new Point(fromX, fromY);
  143.         var obj:Object;
  144.         n = 0;
  145.         g.moveTo(pos.x, pos.y);
  146.         while (true) {
  147.             obj = sl.next();
  148.             n += obj.length;
  149.             if (n > l) {
  150.                 pos.x = toX;
  151.                 pos.y = toY;
  152.                 s = step(g, pos, s);
  153.                 break;
  154.             }else {
  155.                 pos.offset(obj.v.x, obj.v.y);
  156.                 s = step(g, pos, s);
  157.             }
  158.         }
  159.     }
  160.     private static function step(g:Graphics, p:Point, s:Boolean):Boolean {
  161.         if (s) {
  162.             g.lineTo(p.x, p.y);
  163.         }else {
  164.             g.moveTo(p.x, p.y);
  165.         }
  166.         return !s;
  167.     }
  168. }
  169. class SimpleList {
  170.     private var currentElement:ListElement;
  171.     private var appendFunc:Function;
  172.     public function SimpleList(data:* = null) {
  173.         if (data != null) {
  174.             _initialize(data);
  175.         }else{
  176.             appendFunc = _initialize;
  177.         }
  178.     }
  179.     public function append(data:*):void {
  180.         appendFunc.call(null, data);
  181.     }
  182.     public function _initialize(data:*):void {
  183.         currentElement = new ListElement(data);
  184.         currentElement.next = currentElement;
  185.         currentElement.prev = currentElement;
  186.         appendFunc = _append;
  187.     }
  188.     public function _append(data:*):void {
  189.         var elem:ListElement = new ListElement(data);
  190.         var tmp:ListElement;
  191.         tmp = currentElement.next;
  192.         currentElement.next = elem;
  193.         elem.prev = currentElement;
  194.         elem.next = tmp;
  195.         tmp.prev = elem;
  196.         
  197.         currentElement = elem;
  198.     }
  199.     public function current():*{
  200.         return currentElement.data;
  201.     }
  202.     public function next():* {
  203.         currentElement = currentElement.next;
  204.         return currentElement.data;
  205.     }
  206.     public function prev():*{
  207.         currentElement = currentElement.prev;
  208.         return currentElement.data;
  209.     }
  210. }
  211. class ListElement {
  212.     public var next:ListElement;
  213.     public var prev:ListElement;
  214.     public var data:*;
  215.     public function ListElement(data:*) {
  216.         this.data = data;
  217.     }
  218. }
noswf
  1. // forked from mtok's Text Engine 縦書きサンプル
  2. package
  3. {
  4.     [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
  5.     import flash.display.Shape;
  6.     import flash.display.Sprite;
  7.     import flash.geom.Rectangle;
  8.     import flash.text.engine.EastAsianJustifier;
  9.     import flash.text.engine.ElementFormat;
  10.     import flash.text.engine.FontDescription;
  11.     import flash.text.engine.TextBlock;
  12.     import flash.text.engine.TextBaseline;
  13.     import flash.text.engine.LineJustification;
  14.     import flash.text.engine.TextElement;
  15.     import flash.text.engine.TextLine;
  16.     import flash.text.engine.TextRotation;
  17.     import flash.system.Capabilities;
  18.     /**
  19.      * ...
  20.      * @author ...
  21.      */
  22.     public class Tategaki extends Sprite
  23.     {
  24.         private var grid:Shape;
  25.         private var screen:Sprite;
  26.         public function Tategaki() 
  27.         {
  28.             grid = new Shape();
  29.             grid.graphics.lineStyle(1, 0xA0EBF3);
  30.             GraphicsUtils.drawGrid(grid.graphics, new Rectangle(00451451), 50);
  31.             GraphicsUtils.drawGrid(grid.graphics, new Rectangle(00451451), 25, Vector.<Number>([2.5,2.5]));
  32.             addChild(grid);
  33.             
  34.             addChild(screen = new Sprite());
  35.             
  36.             grid.x = screen.x = 5;
  37.             grid.y = screen.y = 5;
  38.             
  39.             var japanese:String = "夕暮れてすとは\n\n\tおやまぁ雲のはたてに物ぞ思ふ\nあまつそらなる\n人を恋ふとて";
  40.             
  41.             var textBlock:TextBlock = new TextBlock();
  42.             var font:FontDescription = new FontDescription();
  43.             if (Capabilities.os.search("Mac OS") > -1) { 
  44.                 font.fontName = "小塚明朝";
  45.             } else {
  46.                 font.fontName = "HGP行書体";
  47.             }
  48.             
  49.             var format:ElementFormat = new ElementFormat(font);
  50.             format.fontSize = 50;
  51.             format.locale = "ja";
  52.             format.color = 0x222222;
  53.             textBlock.baselineZero = TextBaseline.IDEOGRAPHIC_CENTER;
  54.             textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_INCLUDING_LAST);
  55.             textBlock.lineRotation = TextRotation.ROTATE_90;
  56.             
  57.             var linePosition:Number = this.stage.stageWidth - 40;
  58.             
  59.             
  60.             textBlock.content = new TextElement(japanese, format);
  61.             
  62.             var previousLine:TextLine = null;
  63.             var textLine:TextLine;
  64.             
  65.             screen.graphics.lineStyle(1, 0xff0000);
  66.             while (true) {
  67.                 textLine = textBlock.createTextLine(previousLine, 450);
  68.                 if (textLine == null)
  69.                     break;
  70.                 textLine.y = 0;
  71.                 textLine.x = linePosition;
  72.                 
  73.                 screen.graphics.moveTo(textLine.x, textLine.y);
  74.                 screen.graphics.lineTo(textLine.x, textLine.height);
  75.                 
  76.                 linePosition -= 50;
  77.                 screen.addChild(textLine);
  78.                 previousLine = textLine;
  79.             }
  80.         }
  81.         
  82.     }
  83. }
  84. import flash.display.Graphics;
  85. import flash.geom.Point;
  86. import flash.geom.Rectangle;
  87. class GraphicsUtils {
  88.     public function GraphicsUtils() {
  89.         ;
  90.     }
  91.     public static function drawGrid(g:Graphics, rect:Rectangle, size:Number, pattern:Vector.<Number> = null):void {
  92.         var i:Number;
  93.         var limitW:Number;
  94.         var limitH:Number;
  95.         
  96.         limitW = rect.x + rect.width;
  97.         limitH = rect.y + rect.height;
  98.         if (pattern == null) {
  99.             i = rect.y;
  100.             while (i < limitH) {
  101.                 g.moveTo(rect.x, i);
  102.                 g.lineTo(limitW, i);
  103.                 i += size;
  104.             }
  105.             i = rect.x;
  106.             while ( i < limitW) {
  107.                 g.moveTo(i, rect.y);
  108.                 g.lineTo(i, limitH);
  109.                 i += size;
  110.             }
  111.         }else {
  112.             i = rect.y;
  113.             while (i < limitH) {
  114.                 drawDotLine(g, rect.x, i, limitW, i, pattern);
  115.                 i += size;
  116.             }
  117.             i = rect.x;
  118.             while (i < limitW) {
  119.                 drawDotLine(g, i, rect.y, i, limitH, pattern);
  120.                 i += size;
  121.             }
  122.         }
  123.     }
  124.     public static function drawDotLine(g:Graphics, fromX:Number, fromY:Number, toX:Number, toY:Number, pattern:Vector.<Number>):void {
  125.         var i:int;
  126.         var n:Number;
  127.         var v:Point = new Point(toX - fromX, toY - fromY);
  128.         var tmp:Point;
  129.         var l:Number = v.length;
  130.         var sl:SimpleList = new SimpleList();
  131.         var s:Boolean = true;
  132.         v.normalize(1);
  133.         
  134.         for (i = 0; i < pattern.length; i++) {
  135.             n = pattern[i];
  136.             tmp = v.clone();
  137.             tmp.normalize(n);
  138.             sl.append({v:tmp, length:n});
  139.         }
  140.         
  141.         
  142.         var pos:Point = new Point(fromX, fromY);
  143.         var obj:Object;
  144.         n = 0;
  145.         g.moveTo(pos.x, pos.y);
  146.         while (true) {
  147.             obj = sl.next();
  148.             n += obj.length;
  149.             if (n > l) {
  150.                 pos.x = toX;
  151.                 pos.y = toY;
  152.                 s = step(g, pos, s);
  153.                 break;
  154.             }else {
  155.                 pos.offset(obj.v.x, obj.v.y);
  156.                 s = step(g, pos, s);
  157.             }
  158.         }
  159.     }
  160.     private static function step(g:Graphics, p:Point, s:Boolean):Boolean {
  161.         if (s) {
  162.             g.lineTo(p.x, p.y);
  163.         }else {
  164.             g.moveTo(p.x, p.y);
  165.         }
  166.         return !s;
  167.     }
  168. }
  169. class SimpleList {
  170.     private var currentElement:ListElement;
  171.     private var appendFunc:Function;
  172.     public function SimpleList(data:* = null) {
  173.         if (data != null) {
  174.             _initialize(data);
  175.         }else{
  176.             appendFunc = _initialize;
  177.         }
  178.     }
  179.     public function append(data:*):void {
  180.         appendFunc.call(null, data);
  181.     }
  182.     public function _initialize(data:*):void {
  183.         currentElement = new ListElement(data);
  184.         currentElement.next = currentElement;
  185.         currentElement.prev = currentElement;
  186.         appendFunc = _append;
  187.     }
  188.     public function _append(data:*):void {
  189.         var elem:ListElement = new ListElement(data);
  190.         var tmp:ListElement;
  191.         tmp = currentElement.next;
  192.         currentElement.next = elem;
  193.         elem.prev = currentElement;
  194.         elem.next = tmp;
  195.         tmp.prev = elem;
  196.         
  197.         currentElement = elem;
  198.     }
  199.     public function current():*{
  200.         return currentElement.data;
  201.     }
  202.     public function next():* {
  203.         currentElement = currentElement.next;
  204.         return currentElement.data;
  205.     }
  206.     public function prev():*{
  207.         currentElement = currentElement.prev;
  208.         return currentElement.data;
  209.     }
  210. }
  211. class ListElement {
  212.     public var next:ListElement;
  213.     public var prev:ListElement;
  214.     public var data:*;
  215.     public function ListElement(data:*) {
  216.         this.data = data;
  217.     }
  218. }
noswf
  1. // forked from mtok's Text Engine 縦書きサンプル
  2. package
  3. {
  4.     [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="0")]
  5.     import flash.display.Shape;
  6.     import flash.display.Sprite;
  7.     import flash.geom.Rectangle;
  8.     import flash.text.engine.EastAsianJustifier;
  9.     import flash.text.engine.ElementFormat;
  10.     import flash.text.engine.FontDescription;
  11.     import flash.text.engine.TextBlock;
  12.     import flash.text.engine.TextBaseline;
  13.     import flash.text.engine.LineJustification;
  14.     import flash.text.engine.TextElement;
  15.     import flash.text.engine.TextLine;
  16.     import flash.text.engine.TextRotation;
  17.     import flash.system.Capabilities;
  18.     /**
  19.      * ...
  20.      * @author ...
  21.      */
  22.     public class Tategaki extends Sprite
  23.     {
  24.         private var grid:Shape;
  25.         private var screen:Sprite;
  26.         public function Tategaki() 
  27.         {
  28.             grid = new Shape();
  29.             grid.graphics.lineStyle(1, 0xA0EBF3);
  30.             GraphicsUtils.drawGrid(grid.graphics, new Rectangle(00451451), 50);
  31.             GraphicsUtils.drawGrid(grid.graphics, new Rectangle(00451451), 25, Vector.<Number>([2.5,2.5]));
  32.             addChild(grid);
  33.             
  34.             addChild(screen = new Sprite());
  35.             
  36.             grid.x = screen.x = 5;
  37.             grid.y = screen.y = 5;
  38.             
  39.             var japanese:String = "夕暮れは\n雲のはたてに物ぞ思ふ\nあまつそらなる\n人を恋ふとて";
  40.             
  41.             var textBlock:TextBlock = new TextBlock();
  42.             var font:FontDescription = new FontDescription();
  43.             if (Capabilities.os.search("Mac OS") > -1) { 
  44.                 font.fontName = "小塚明朝";
  45.             } else {
  46.                 font.fontName = "HGP行書体";
  47.             }
  48.             
  49.             var format:ElementFormat = new ElementFormat(font);
  50.             format.fontSize = 50;
  51.             format.locale = "ja";
  52.             format.color = 0x222222;
  53.             textBlock.baselineZero = TextBaseline.IDEOGRAPHIC_CENTER;
  54.             textBlock.textJustifier = new EastAsianJustifier("ja", LineJustification.ALL_INCLUDING_LAST);
  55.             textBlock.lineRotation = TextRotation.ROTATE_90;
  56.             
  57.             var linePosition:Number = this.stage.stageWidth - 40;
  58.             
  59.             
  60.             textBlock.content = new TextElement(japanese, format);
  61.             
  62.             var previousLine:TextLine = null;
  63.             var textLine:TextLine;
  64.             
  65.             screen.graphics.lineStyle(1, 0xff0000);
  66.             while (true) {
  67.                 textLine = textBlock.createTextLine(previousLine, 450);
  68.                 if (textLine == null)
  69.                     break;
  70.                 textLine.y = 0;
  71.                 textLine.x = linePosition;
  72.                 
  73.                 screen.graphics.moveTo(textLine.x, textLine.y);
  74.                 screen.graphics.lineTo(textLine.x, textLine.height);
  75.                 
  76.                 linePosition -= 50;
  77.                 screen.addChild(textLine);
  78.                 previousLine = textLine;
  79.             }
  80.         }
  81.         
  82.     }
  83. }
  84. import flash.display.Graphics;
  85. import flash.geom.Point;
  86. import flash.geom.Rectangle;
  87. class GraphicsUtils {
  88.     public function GraphicsUtils() {
  89.         ;
  90.     }
  91.     public static function drawGrid(g:Graphics, rect:Rectangle, size:Number, pattern:Vector.<Number> = null):void {
  92.         var i:Number;
  93.         var limitW:Number;
  94.         var limitH:Number;
  95.         
  96.         limitW = rect.x + rect.width;
  97.         limitH = rect.y + rect.height;
  98.         if (pattern == null) {
  99.             i = rect.y;
  100.             while (i < limitH) {
  101.                 g.moveTo(rect.x, i);
  102.                 g.lineTo(limitW, i);
  103.                 i += size;
  104.             }
  105.             i = rect.x;
  106.             while ( i < limitW) {
  107.                 g.moveTo(i, rect.y);
  108.                 g.lineTo(i, limitH);
  109.                 i += size;
  110.             }
  111.         }else {
  112.             i = rect.y;
  113.             while (i < limitH) {
  114.                 drawDotLine(g, rect.x, i, limitW, i, pattern);
  115.                 i += size;
  116.             }
  117.             i = rect.x;
  118.             while (i < limitW) {
  119.                 drawDotLine(g, i, rect.y, i, limitH, pattern);
  120.                 i += size;
  121.             }
  122.         }
  123.     }
  124.     public static function drawDotLine(g:Graphics, fromX:Number, fromY:Number, toX:Number, toY:Number, pattern:Vector.<Number>):void {
  125.         var i:int;
  126.         var n:Number;
  127.         var v:Point = new Point(toX - fromX, toY - fromY);
  128.         var tmp:Point;
  129.         var l:Number = v.length;
  130.         var sl:SimpleList = new SimpleList();
  131.         var s:Boolean = true;
  132.         v.normalize(1);
  133.         
  134.         for (i = 0; i < pattern.length; i++) {
  135.             n = pattern[i];
  136.             tmp = v.clone();
  137.             tmp.normalize(n);
  138.             sl.append({v:tmp, length:n});
  139.         }
  140.         
  141.         
  142.         var pos:Point = new Point(fromX, fromY);
  143.         var obj:Object;
  144.         n = 0;
  145.         g.moveTo(pos.x, pos.y);
  146.         while (true) {
  147.             obj = sl.next();
  148.             n += obj.length;
  149.             if (n > l) {
  150.                 pos.x = toX;
  151.                 pos.y = toY;
  152.                 s = step(g, pos, s);
  153.                 break;
  154.             }else {
  155.                 pos.offset(obj.v.x, obj.v.y);
  156.                 s = step(g, pos, s);
  157.             }
  158.         }
  159.     }
  160.     private static function step(g:Graphics, p:Point, s:Boolean):Boolean {
  161.         if (s) {
  162.             g.lineTo(p.x, p.y);
  163.         }else {
  164.             g.moveTo(p.x, p.y);
  165.         }
  166.         return !s;
  167.     }
  168. }
  169. class SimpleList {
  170.     private var currentElement:ListElement;
  171.     private var appendFunc:Function;
  172.     public function SimpleList(data:* = null) {
  173.         if (data != null) {
  174.             _initialize(data);
  175.         }else{
  176.             appendFunc = _initialize;
  177.         }
  178.     }
  179.     public function append(data:*):void {
  180.         appendFunc.call(null, data);
  181.     }
  182.     public function _initialize(data:*):void {
  183.         currentElement = new ListElement(data);
  184.         currentElement.next = currentElement;
  185.         currentElement.prev = currentElement;
  186.         appendFunc = _append;
  187.     }
  188.     public function _append(data:*):void {
  189.         var elem:ListElement = new ListElement(data);
  190.         var tmp:ListElement;
  191.         tmp = currentElement.next;
  192.         currentElement.next = elem;
  193.         elem.prev = currentElement;
  194.         elem.next = tmp;
  195.         tmp.prev = elem;
  196.         
  197.         currentElement = elem;
  198.     }
  199.     public function current():*{
  200.         return currentElement.data;
  201.     }
  202.     public function next():* {
  203.         currentElement = currentElement.next;
  204.         return currentElement.data;
  205.     }
  206.     public function prev():*{
  207.         currentElement = currentElement.prev;
  208.         return currentElement.data;
  209.     }
  210. }
  211. class ListElement {
  212.     public var next:ListElement;
  213.     public var prev:ListElement;
  214.     public var data:*;
  215.     public function ListElement(data:*) {
  216.         this.data = data;
  217.     }
  218. }
noswf
  1. package{
  2.     import flash.display.Sprite;
  3.     import flash.display.StageAlign;
  4.     import flash.display.StageScaleMode;
  5.     
  6.     import flash.net.URLLoader;
  7.     import flash.net.URLRequest;
  8.     
  9.     import flashx.textLayout.compose.StandardFlowComposer;
  10.     import flashx.textLayout.container.DisplayObjectContainerController;
  11.     import flashx.textLayout.container.IContainerController;
  12.     
  13.     import flashx.textLayout.elements.TextFlow;
  14.     import flashx.textLayout.conversion.TextFilter;
  15.     
  16.     import flash.events.Event;
  17.     import flash.events.IOErrorEvent;
  18.     
  19.     [SWF(width = "460", height = "300", backgroundColor = "0xFFFFFF")]
  20.     
  21.     public class Index2 extends Sprite
  22.     {
  23.         private static const MARKUP:String = "test.xml";
  24.         
  25.         private var _textFlow:TextFlow;
  26.         
  27.         public function Index2()
  28.         {
  29.             // ステージ設定
  30.             stage.scaleMode = StageScaleMode.NO_SCALE;
  31.             stage.align = StageAlign.TOP_LEFT;
  32.             
  33.             // テキストレイアウト読み込み
  34.             var loader:URLLoader = new URLLoader();
  35.             loader.load(new URLRequest(MARKUP));
  36.             loader.addEventListener(Event.COMPLETE,completeHandler);
  37.             loader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
  38.             
  39.         }
  40.         // 読み込み完了
  41.         private function completeHandler(e:Event):void
  42.         {
  43.             _textFlow = TextFilter.importToFlow(e.target.data, TextFilter.TEXT_LAYOUT_FORMAT);
  44.             _textFlow.flowComposer.addController(new DisplayObjectContainerController(this,stage.stageWidth, stage.stageHeight));
  45.             _textFlow.flowComposer.updateAllContainers();        
  46.             
  47.         }
  48.         // 読み込みエラー
  49.         private function ioErrorHandler(e:IOErrorEvent):void
  50.         {
  51.             var markup:String = "<?xml version='1.0' encoding='utf-8'?><flow:TextFlow paddingRight='20' paddingTop='20' paddingLeft='0' blockProgression='rl' whiteSpaceCollapse='preserve' xmlns:flow='http://ns.adobe.com/textLayout/2008'><flow:p><flow:span renderingMode='normal' locale='ja' color='0xff0000' trackingRight='0' fontSize='20' fontFamily='_ゴシック'>読み込み失敗</flow:span></flow:p></flow:TextFlow>";
  52.             _textFlow = TextFilter.importToFlow(markup, TextFilter.TEXT_LAYOUT_FORMAT);
  53.             _textFlow.flowComposer.addController(new DisplayObjectContainerController(this,stage.stageWidth, stage.stageHeight));
  54.             _textFlow.flowComposer.updateAllContainers();        
  55.             
  56.             
  57.         }
  58.     }
  59. }
noswf
Get Adobe Flash Player