Actionscript 3 img在as3中自动调整大小
我有一个视频播放器,每个视频都有thunb 问题在于图片的大小。。。将原始图片大小导入播放器。。。 我怎样才能解决这个问题? 谢谢你,对我的英语感到抱歉 这是as3代码:Actionscript 3 img在as3中自动调整大小,actionscript-3,image,resize,Actionscript 3,Image,Resize,我有一个视频播放器,每个视频都有thunb 问题在于图片的大小。。。将原始图片大小导入播放器。。。 我怎样才能解决这个问题? 谢谢你,对我的英语感到抱歉 这是as3代码: /** * VideoThumb * Author: firecode * Description: This class is linked to the VideoThumb MovieClip in the Library. */ package firecode { /** import dis
/**
* 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;
}
}
}
/**
*视频拇指
*作者:消防代码
*描述:此类链接到库中的VideoThumb MovieClip。
*/
包装防火代码
{
/**导入显示*/
导入flash.display.Sprite;
导入flash.display.Loader;
/**导入事件*/
导入flash.events.MouseEvent;
/**进口净额*/
导入flash.net.URLRequest
/**导入文本*/
导入flash.text.TextFormat;
/**输入数学*/
导入flash.geom.ColorTransform;
/**这个类扩展了一个Sprite类*/
公共类VideoThumb扩展了Sprite
{
private var_thumb:Loader=new Loader();/**用于视频缩略图的图像容器*/
私有变量_id:int=0;/**视频的id*/
私有变量_cat:int=0;/**所选类别*/
private var_selected:Boolean=false;/**如果在播放列表中选择了视频*/
/**建造师*/
公共功能VideoThumb()
{
/**在MovieClip上更改鼠标光标*/
this.buttonMode=true;
/**设置文本字段*/
_thumbText.multiline=true;
_thumbText.wordWrap=true;
/**格式化文本字段*/
_setTextFormat(新文本格式(“Arial”));
/**从类别文本字段中删除鼠标事件*/
_thumbText.mouseEnabled=false;
/**无法使用鼠标选择文本字段*/
_thumbText.selective=false;
/**设置并添加到显示列表视频的图像*/
_拇指x=9;
_拇指y=11;
_thumb.mouseEnabled=false;
_thumb.mouseChildren=false;
addChild(_拇指);
/**设置事件*/
this.addEventListener(MouseEvent.MOUSE_OVER,MouseOverThumb,false,0,true);
this.addEventListener(MouseEvent.MOUSE_OUT,MouseOutThumb,false,0,true);
}
/**更改鼠标悬停时视频拇指的外观*/
私有函数MouseOverThumb($e:MouseEvent=null):无效
{
如果(_selected==false)
{
_thumbBackground.gotoAndStop(2);
}否则{
_thumbBackground.gotoAndStop(3);
}
SetThumbOver();
}
/**更改鼠标移出时视频拇指的外观*/
私有函数MouseOutThumb($e:MouseEvent=null):void
{
/**如果已在播放列表中选择此拇指,请不要更改它*/
如果(_selected==false)
{
_thumbBackground.gotoAndStop(1);
SetThumbOut();
}否则{
_thumbBackground.gotoAndStop(3);
SetThumbOver();
}
}
/**设置视频拇指*/
公共函数SetupThumb($cat:int,$id:int):无效
{
_id=$id;
_cat=$cat;
_load(新的URLRequest(XMLData.GetThumbLink($cat,$id));
SetThumbOut();
}
/**返回视频拇指的id*/
公共函数GetId():int
{
返回_id;
}
/**将此视频拇指标记为选中*/
公共函数SetSelected($value:Boolean):void
{
_所选=$value
如果(!\u选中)
{
MouseOutThumb();
}否则{
_thumbBackground.gotoAndStop(3);
MouseOverThumb();
}
}
/**如果选择或未选择此视频缩略图,则返回*/
公共函数GetSelected():布尔值
{
返回(已选择);;
}
/**在鼠标悬停时格式化描述文本*/
私有函数SetThumbOver():void
{
var_设置:Object=XMLData.GetShortOver();
_thumbText.htmlText=''+XMLData.GetVideoTitle(_cat,_id)+'-'+XMLData.GetShortDescription(_cat,_id)+'';
}
/**设置鼠标悬停时描述文本的格式*/
私有函数SetThumbOut():void
{
var_设置:Object=XMLData.GetShortOut();
_thumbText.htmlText=''+XMLData.GetVideoTitle(_cat,_id)+'-'+XMLData.GetShortDescription(_cat,_id)+'';
}
/**调整元素的大小和位置*/
公共函数ResizeAndPosition($width:Number):无效
{
_thumbText.width=($width-_thumbText.x)-10;
_thumbBackground.width=$width-10;
}
}
}
将拇指加载到应用程序后,应调整拇指的大小。可以修改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
}