img auto在as3中调整大小

时间:2011-07-11 17:18:38

标签: actionscript-3 image resize

我有一个视频播放器,每个视频都有一个thunb 问题在于图片大小...它将原始图片大小导入播放器...... 我怎么能解决这个问题? 谢谢你,对我的英语感到抱歉。

这是as3代码:

    /**
 * VideoThumb
 * Author: firecode
 * Description: This class is linked to the VideoThumb MovieClip in the Library.
 */
package firecode
{
    /** import display              */
    import flash.display.Sprite;
    import flash.display.Loader;

    /** import events               */
    import flash.events.MouseEvent;

    /** import net                  */
    import flash.net.URLRequest

    /** import text                 */
    import flash.text.TextFormat;

    /** import math                 */
    import flash.geom.ColorTransform;

    /** this class extends a Sprite Class   */
    public class VideoThumb extends Sprite
    {
        private var _thumb      :Loader  = new Loader();    /** image container for the thumbnail of the video */
        private var _id         :int     = 0;               /** id of the video                                */
        private var _cat        :int     = 0;               /** selected category                              */
        private var _selected   :Boolean = false;           /** if video has been selected in the playlist     */

        /** constructor */
        public function VideoThumb()
        {
            /** change cursor on mouse over MovieClip */
            this.buttonMode = true; 

            /** setup the text field */
            _thumbText.multiline = true;
            _thumbText.wordWrap  = true;

            /** format the text field */
            _thumbText.setTextFormat(new TextFormat("Arial"));

            /** remove the mouse events from the category textfield */
            _thumbText.mouseEnabled = false;

            /** text field can't be selected with the mouse  */
            _thumbText.selectable = false;

            /** setup and add to displaylist the image thumb of the video */
            _thumb.x=9;
            _thumb.y=11;
            _thumb.mouseEnabled  = false;
            _thumb.mouseChildren = false;
            addChild(_thumb);

            /** setup events */
            this.addEventListener(MouseEvent.MOUSE_OVER, MouseOverThumb,  false, 0, true);
            this.addEventListener(MouseEvent.MOUSE_OUT,  MouseOutThumb,   false, 0, true);
        }

        /** changes the appereance of the video thumb on mouse over */
        private function MouseOverThumb($e:MouseEvent=null):void
        {
            if (_selected == false)
            {
                _thumbBackground.gotoAndStop(2);

            }else{
                _thumbBackground.gotoAndStop(3);

            }
            SetThumbOver();
        }

        /** changes the appereance of the video thumb on mouse out */ 
        private function MouseOutThumb($e:MouseEvent=null):void
        {
            /** if this thumb has been selected in the playlist don't change it */
            if (_selected == false)
            {
                _thumbBackground.gotoAndStop(1);
                SetThumbOut();
            }else{
                _thumbBackground.gotoAndStop(3);
                SetThumbOver();
            }
        }       

        /** setup video thumb */
        public function SetupThumb($cat:int, $id:int):void
        {
            _id  = $id;
            _cat = $cat;

            _thumb.load(new URLRequest(XMLData.GetThumbLink($cat, $id)));       

            SetThumbOut();
        }

        /** return the id of the video thumb */
        public function GetId():int
        {
            return _id;
        }

        /** flag this video thumb as selected */
        public function SetSelected($value:Boolean):void
        {
            _selected = $value

            if (!_selected) 
            {
                MouseOutThumb();
            }else{
                _thumbBackground.gotoAndStop(3);
                MouseOverThumb();
            }
        }

        /** returns if this video thumb is selected or not */
        public function GetSelected():Boolean
        {
            return _selected;
        }       

        /** formats the description text on mouse over */
        private function SetThumbOver():void
        {
            var _settings:Object = XMLData.GetShortOver();
            _thumbText.htmlText = '<b><font size="'+ _settings.title_fontsize +'" color="'+_settings.title_color+'">'+XMLData.GetVideoTitle(_cat, _id)+'</font></b> <font size="'+_settings.description_fontsize+'" color="'+_settings.description_color+'"> - ' + XMLData.GetShortDescription(_cat, _id)+'</font>';            

        }

        /** formats the description text on mouse out */
        private function SetThumbOut():void
        {
            var _settings:Object = XMLData.GetShortOut();
            _thumbText.htmlText = '<b><font size="'+ _settings.title_fontsize +'" color="'+_settings.title_color+'">'+XMLData.GetVideoTitle(_cat, _id)+'</font></b> <font size="'+_settings.description_fontsize+'" color="'+_settings.description_color+'"> - ' + XMLData.GetShortDescription(_cat, _id)+'</font>';
        }       


        /** resize and position the elements */
        public function ResizeAndPosition($width:Number):void
        {
            _thumbText.width       = ( $width- _thumbText.x ) - 10;
            _thumbBackground.width = $width-10;
        }

    }
}

1 个答案:

答案 0 :(得分:0)

将拇指加载到您的应用程序后,您应该调整大小。您的SetupThumb功能可以修改:

    /** setup video thumb */
    public function SetupThumb($cat:int, $id:int):void
    {
        _id  = $id;
        _cat = $cat;
        _thumb.contentLoaderInfo.addEventListener(Event.COMPLETE, resizeThumb);
        _thumb.load(new URLRequest(XMLData.GetThumbLink($cat, $id)));

        SetThumbOut();
    }

    private function resizeThumb(e:Event):void {
        _thumb.content.width=100; // You may specify any other size
        //_thumb.content.heigth=100;
        _thumb.content.scaleY=_thumb.content.scaleX; // Resize proportionaly
    }