第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

瀏覽器窗口尺寸改變時(shí)圖片自動(dòng)重新定位

標(biāo)簽:
資訊

俗话说:拳不离手,曲不离口。学过的技能不用,放长了就生疏了,今天以前的同事问我:用户改变浏览器窗口尺寸时,flash中的图片如何重新定位于4个角上。花了近一刻钟才回忆想来:stage有Resize事件,呵呵代码如下:1.先把加载图片的逻辑封装一下:

package  { 
    import flash.display.Sprite;
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.display.Bitmap;
    import flash.events.IOErrorEvent;
    import flash.system.LoaderContext;
     
    public class LoadImage extends Sprite {
         
        private var _imgWidth:int;
        private var _imgHeight:int;
         
        public function LoadImage(url:String,imgWidth:int=380,imgHeight:int=305) {
             
            this._imgWidth = imgWidth;
            this._imgHeight = imgHeight;
             
            var _request:URLRequest = new URLRequest(url);
            var _loader:Loader = new Loader();
            var _lc:LoaderContext = new LoaderContext(true);
            _loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
            _loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,loadIO_Error);
            _loader.load(_request,_lc);
             
        }      
         
        private function loadComplete(e:Event):void
        {
            //trace("loadComplete");
            var li:LoaderInfo = e.currentTarget as LoaderInfo;
            var bmp:Bitmap = li.content as Bitmap;
            bmp.height = _imgHeight;
            bmp.width = _imgWidth;
            addChild(bmp);
        }
         
        private function loadIO_Error(e:IOErrorEvent):void
        {
            trace("load error!");
        }
    }  
}

2.主文档类

package  {
     
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
     
     
    public class ResizeDemo extends MovieClip {
         
        private var _top_left:LoadImage; //左上 的图片
        private var _top_right:LoadImage; //右上 的图片
        private var _bottom_left:LoadImage; //左下 的图片
        private var _bottom_right:LoadImage; //右下 的图片
        private var _center:LoadImage; //中心的图片
        private var _WIDTH:int; //舞台的宽度
        private var _HEIGHT:int; //舞台的高度
         
        public function ResizeDemo() {
            // constructor code
             
            if (stage)
            {
                init();
            }
            else
            {
                stage.addEventListener(Event.ADDED_TO_STAGE,init);
            }
        }
         
        private function init(e:Event=null)
        {
            stage.removeEventListener(Event.ADDED_TO_STAGE,init);
            stage.addEventListener(Event.RESIZE,reSizeHandler);
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
             
             
            //加载图片
            _top_left = new LoadImage("top_left.jpg",100,150);
            _top_right = new LoadImage("top_right.jpg",100,150);
            _bottom_left = new LoadImage("bottom_left.jpg",100,150);
            _bottom_right = new LoadImage("bottom_right.jpg",100,150);
            _center = new LoadImage("center.jpg",200,300);
             
             
            addChild(_top_left);
            addChild(_top_right);
            addChild(_bottom_left);
            addChild(_bottom_right);
            addChild(_center);
             
            adjustPosition();
             
             
        }
         
        private function reSizeHandler(e:Event=null)
        {
            adjustPosition();
        }
         
        //调整位置
        private function adjustPosition()
        {
            _WIDTH = stage.stageWidth;
            _HEIGHT = stage.stageHeight;
             
            trace("_WIDTH =",_WIDTH);
            trace("_HEIGHT =",_HEIGHT);
            trace("_top_left.width =",_top_left.width);
             
            //定位 左上的图片
            _top_left.x = _top_left.y = 0;
             
            //定位 右上的图片
            _top_right.x = _WIDTH - _top_left.width;
            _top_right.y = 0;
             
            //定位 左下的图片
            _bottom_left.x = 0;
            _bottom_left.y = _HEIGHT - _bottom_left.height;
             
            //定位 右下的图片
            _bottom_right.x = _WIDTH - _bottom_right.width;
            _bottom_right.y = _HEIGHT - _bottom_right.height;
             
            //定位中心的图片
            _center.x = (_WIDTH - _center.width)/2;
            _center.y = (_HEIGHT - _center.height)/2;
        }
         
    }
     
}

點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專(zhuān)欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消