好的,我的想法让我很难过。我知道这可能看起来像一个简单的问题,我无法理解为什么我无法弄明白但是我不能这么做而且我只是放弃了。这是问题所在:
我有一个精灵容器,它应该为视频提供一堆缩略图。我可以用所有视频和整个作品填充容器,但很明显,如果我添加一堆视频,它将超过flash文档的大小,所以我需要添加一个UIScrollBar(我做了)现在滚动条目标设置为容器,但不允许我滚动,如果我正确,这是因为容器没有设置高度。所以我试图设置这个容器的高度,但第二次我尝试设置高度甚至宽度我以前所能看到的所有缩略图都消失了!这就好像大小被设置为0,当它不是我甚至试图将它设置为指定的大小只是为了测试而没有。无论如何,如果有人可以提供帮助,那么我的代码就是我真的很感激!提前谢谢!
import fl.controls.UIScrollBar;
var videoList:XMLList;
var numVideos:Number;
var current_Video:Number = 0;
var video_position:Number;
var video_paused:Boolean;
var xmlPlaylist:String;
//XML File setup
var playlist_xml:XML;
var myLoader:URLLoader = new URLLoader();
//Playlist setup
var thumb_width:Number;
var thumb_height:Number;
var thumbs_x:Number;
var thumbs_y:Number;
var main_container:Sprite;
var thumbs:Sprite;
var scrollbar:UIScrollBar;
//Loader Data
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
function loaderComplete(e:Event):void
{
var myQueryStrings = this.loaderInfo.parameters;
xmlPlaylist = myQueryStrings.pList;
myLoader.load(new URLRequest(xmlPlaylist + "?uniq=" + new Date().getTime()));
}
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void {
playlist_xml = new XML(e.target.data);
numVideos = playlist_xml.video.length();
videoList = playlist_xml.video;
thumb_width = playlist_xml.@thumb_width;
thumb_height = playlist_xml.@thumb_height;
thumbs_x = playlist_xml.@thumbs_x;
thumbs_y = playlist_xml.@thumbs_y;
current_Video = Math.round(Math.random()*(numVideos-1))+1;
current_Video--;
startPlayer();
}
function startPlayer()
{
makeContainers();
callThumbs();
setVideo(current_Video);
}
function makeContainers():void
{
main_container = new Sprite();
addChild(main_container);
thumbs = new Sprite();
thumbs.addEventListener(MouseEvent.CLICK, playVideo);
thumbs.addEventListener(MouseEvent.MOUSE_OVER, onOver);
thumbs.addEventListener(MouseEvent.MOUSE_OUT, onOut);
thumbs.x = thumbs_x;
thumbs.y = thumbs_y;
这是问题所在:(如果我注释掉这段代码,它会显示缩略图)
thumbs.width = thumb_width;
thumbs.height = (thumb_height + 11) * 3;
thumbs.buttonMode = true;
main_container.addChild(thumbs);
scrollbar = new UIScrollBar();
scrollbar.x = thumbs_x + thumb_width + 2;
scrollbar.y = thumbs_y;
scrollbar.setSize(25, (thumb_height + 11) * 3);
scrollbar.visible = true;
scrollbar.scrollTarget = thumbs;
main_container.addChild(scrollbar);
}
function callThumbs():void
{
for (var i:Number = 0; i (less than) numVideos; i++) //For some reason Stack Overflow isnt allowing me to put the symbol less than so i just typed it in...
{
var thumb_url = videoList[i].@thumb;
var thumb_loader = new Loader();
thumb_loader.name = i;
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
thumb_loader.y = (thumb_height + 11) * i;
}
}
function thumbLoaded(e:Event):void
{
var my_thumb:Loader = Loader(e.target.loader);
thumbs.addChild(my_thumb);
}
function playVideo(e:MouseEvent):void
{
setVideo(e.target.name);
}
function onOver (e:MouseEvent):void
{
var my_thumb:Loader = Loader(e.target);
my_thumb.alpha = 0.5;
}
function onOut (e:MouseEvent):void
{
var my_thumb:Loader = Loader (e.target);
my_thumb.alpha = 1;
}
function setVideo(current_Video)
{
var display:String = videoList[current_Video].@title;
var video:String = videoList[current_Video].@url;
txt_Display.text = display;
flvPlayer.source = video;
}
stop();
答案 0 :(得分:11)
这很容易。您正在创建Sprite,添加侦听器,设置坐标。精灵仍然是空的。然后设置宽度和高度,它们将转换为scaleX和scaleY。在空精灵上,这会弄乱转换矩阵,精灵永远不会出现。仅在非空精灵上设置宽度,高度或比例X / Y.