简体   繁体   中英

Why this rect is not drawn?

My actionscript:

package
{
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;

    import spark.core.SpriteVisualElement;

    public class SimpleFill extends SpriteVisualElement
    {
        public function SimpleFill()
        {
            //var sprite:Sprite = new Sprite();
            //var graphics:Graphics = sprite.graphics;
            graphics.beginFill(0x0000FF, 1);
            graphics.drawRect(10, 10, width, height);
            graphics.endFill();
            //addChild(sprite);
        }
    }
}

I also tried with the commented lines uncommented, but does not work either.

My MXML:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="640" minHeight="480"
               creationComplete="initApp()">

    <fx:Script>
        <![CDATA[
            public function initApp():void
            {
                addElement(new SimpleFill());
            }
        ]]>
    </fx:Script>

</s:Application>

any idea why it isn't drawing?

Are you sure width & height in SimpleFill are not equal to zero? I'd check that first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM