zoukankan      html  css  js  c++  java
  • as3 内容自适应容器大小

    package {
        import flash.display.Sprite;
        import flash.display.Bitmap;
        import flash.display.Graphics;
            
        /*示例内容自适应盒子的大小*/
        [SWF(width=800, height=600)]
        public class SampleAdjustSize extends Sprite {
            private var borderWid:uint=600;//边框宽
            private var borderHei:uint=400;//边框高
            private var box:Sprite;
            private var btm:Bitmap;
            
            [Embed(source="img.jpg")]    //嵌入864x684宽高图一张
            public var IMG:Class;
    
            public function SampleAdjustSize():void 
            {
                init();
            }
            
            private function init():void
            {
                initBorder();
                btm = new IMG() as Bitmap;
                adjustSize();
            }
            
            private function initBorder():void
            {
                box = new Sprite();
                var g:Graphics = box.graphics;
                g.lineStyle(1, 0x000000);
                g.drawRect(0, 0, borderWid, borderHei);
                addChild(box);
                box.x = this.stage.stageWidth / 2 - box.width /2;
                box.y = this.stage.stageHeight / 2 - box.height / 2;
            }
            
            private function adjustSize():void
            {
                if(btm.width < box.width && btm.height < box.height) return;
                var px:Number = box.width / btm.width;
                var py:Number = box.height / btm.height;
                var scale:Number = px > py ? py :px;
                btm.width = btm.width * scale;
                btm.height = btm.height * scale;
                box.addChild(btm);
            }
        }
    }
  • 相关阅读:
    大小端模式
    深入理解c/c++ 内存对齐
    示波器使用
    C结构体
    51单片机内存问题
    S5PV210启动过程详解1
    程序中内存从哪里来
    再论typedef
    ARM体系结构总结
    MMU实验实验
  • 原文地址:https://www.cnblogs.com/playerlife/p/2727418.html
Copyright © 2011-2022 走看看