SimpleCanvas.as

package  {
    import mx.core.UIComponent
    import flash.display.Bitmap

    public class SimpleCanvas extends UIComponent
    {
        [Embed(source = 'jsplatformer1-smiley.jpg')]
        public static const SmileImage:Class        


        private var SmileBmp:Bitmap = null;

        private var xD:int = 1
        private var yD:int = 1


        public function init():void
        {
            SmileBmp = new SmileImage()
            addChild( SmileBmp )
        }

        public function onTick():void
        {
            if (SmileBmp == null)
                return;

            SmileBmp.x += 1*xD;
            SmileBmp.y += 1*yD;


            if (SmileBmp.x + SmileBmp.width >= width)
            {
                xD = -1
            }else if (SmileBmp.x <= 0)
            {
                xD = 1
            }

            if (SmileBmp.y + SmileBmp.height >= height)
            {
                yD = -1
            }else if (SmileBmp.y <= 0)
            {
                yD = 1
            }
 
        }
    }
}

Comments