开发者

Textbox disappears when I change width of initial sprite

开发者 https://www.devze.com 2023-02-02 18:49 出处:网络
I\'m attempting to draw a text box on the screen.If I assign width and height to any value, as in the code below, I don\'t see anything drawn.Why is this?What is the use of width and height?Adobe\'s d

I'm attempting to draw a text box on the screen. If I assign width and height to any value, as in the code below, I don't see anything drawn. Why is this? What is the use of width and height? Adobe's docs say it's the width/height of the sprite in pixels. Why would that occlude or prevent the drawing of a textbox or another box? I assumed the width/height would set the area that this sprite could be drawn upon, but based on this, I'm probably wrong.

Thanks in advance.

-Nick

package {

import flash.display.Sprite;
import flash.events.Event;
import mx.core.* ;
import mx.collections.* ;
import flash.display.* ;
import flash.text.* ;

[SWF(width=1000,height=500)]
public class BareBones extends Sprite
{
    public var backBuffer:BitmapData;
    public var clearColor:uint = 0xFF0043AB;
    public var display_txt:TextField;
    public var i:uint = 0
    public function BareBones()
    { 
        addEventListener(Event.ENTER_FRAME, step);
        width = 1000;
     开发者_如何学运维   height = 500;
        display_txt = new TextField();
        display_txt.text = "Hello World!";
        addChild(display_txt);
    }

    private function step(event:Event) : void
    {
        i++;
        display_txt.text = i.toString();
    }
}

}


When you set width and height in the constructor, you're actually affecting the scaleX and scaleY variables, which in turn affect root's transform.matrix.

In order to know how to set scaleX, Flash works off the content that is inside the clip. For example if you have a MovieClip with a 100x100 box in it, and you set width = 200, Flash will calculate that you mean scaleX = 2.

However you are setting width and height on a clip with nothing in it. The consequence is that scaleX and scaleY are both being set to 0.

0

精彩评论

暂无评论...
验证码 换一张
取 消