Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use VGroup or HGroup in pure actionscript3?
    primarykey
    data
    text
    <p>I'm developing a flash app by using free Flex SDK and text editor and compiling in command line.<br> <br> I want to use VGroup or HGroup in my actionscript to manage positions of DisplayObjects.<br> <br> I wrote the following code:</p> <pre><code>import spark.components.* import flash.text.* var group:VGroup = new VGroup; var text:TextField = new TextField text.text = 'abc'; var sprite = new Sprite; sprite.graphics.lineStyle(2, 0x000000); sprite.graphics.drawRect(0, 0, 100, 100); stage.addChild(group); group.addElement(sprite); // runtime error group.addElement(text); // compile error </code></pre> <p><br> But adding Sprite to VGroup causes runtime error: <br></p> <pre><code>TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Sprite to mx.core.IVisualElement. </code></pre> <p><br> And adding TextField to VGroup causes compile error: <br></p> <pre><code>Error: Implicit coercion of a value of type flash.text: TextField to an unrelated type mx.core:IVisualElement. </code></pre> <p><br> How to use VGroup or HGroup in pure AS3?<br> What is the difference between DisplayObject and IVisualElement?<br></p> <p><br> UPDATE:</p> <p>I tried the 1st way of www.Flextras.com's answer, SpriteVisualElement and StyleableTextField.<br> I wrote the following code:</p> <pre><code>package { import flash.display.* import spark.core.SpriteVisualElement //import spark.components.supportClasses.StyleableTextField // compile error import spark.components.VGroup import flash.text.* [SWF(backgroundColor=0xffffff, width=500, height=500, frameRate=12)] public class VGroupTest extends Sprite { function VGroupTest() { //var text:StyleableTextField = new StyleableTextField //text.text = 'abc'; var sprite1:SpriteVisualElement = new SpriteVisualElement; sprite1.graphics.lineStyle(2, 0x000000); sprite1.graphics.drawRect(0, 0, 100, 100); sprite1.width = 200 sprite1.height = 200 var sprite2:SpriteVisualElement = new SpriteVisualElement; sprite2.graphics.lineStyle(2, 0xff0000); sprite2.graphics.drawRect(0, 0, 200, 200); sprite2.width = 300 sprite2.height = 300 var group:VGroup = new VGroup; group.gap = 10 group.width = 400 group.height = 400 this.stage.addChild(group); // the following codes show nothing //group.addElement(text); group.addElement(sprite1); group.addElement(sprite2); // the following codes show 2 rectangles //this.stage.addChild(sprite1) //this.stage.addChild(sprite2) } } } </code></pre> <p><br> But<br></p> <pre><code>import spark.components.supportClasses.StyleableTextField </code></pre> <p>caused the following error</p> <pre><code>40 Error: Definition spark.components.supportClasses:StyleableTextField could not be found </code></pre> <p><br> And no SpriteVisualElement is shown on the screen.<br> Am I missing something?<br></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload