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);
            }
        }
    }
  • 相关阅读:
    CSS hack
    字符串中常用的方法
    排序算法
    拾遗
    数组类型检测
    数组常用的方法
    go 文件服务器(标准库) 添加关机,睡眠,退出功能
    go cmd 交互 初始化执行某些命令
    go 内网IP及外网IP获取
    go 快排实现
  • 原文地址:https://www.cnblogs.com/playerlife/p/2727418.html
Copyright © 2011-2022 走看看