开发者

img auto resize in as3

i have a video player with thunb for each video the problem is with the pictures size... its import the orginal pic size to the player... how can i fix that ? thank you and sorry about my english.

this is the as3 code:

    /**
 * 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;
        }

    }
}


You should resize the thumb after it is loaded into your application. Your SetupThumb function can be modified:

    /** 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
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜