actionscript-3 - AS3设置Sprite容器的宽度和高度

标签 actionscript-3 flash-cs5

好的,我的想法让我感到困惑。我知道这看起来像是一个简单的问题,我不明白为什么我不知道为什么,但是我仍然无法放弃,我已经放弃了。这是问题所在:

我有一个Sprite容器,应该可以容纳一堆视频缩略图。我可以用所有视频和整个作品填充容器,但是很明显,如果我添加一堆视频,其大小将超过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();

最佳答案

这很简单。您正在创建Sprite,添加监听器,设置坐标。该子画面仍然为空。然后设置宽度和高度,将其转换为scaleX和scaleY。在空 Sprite 上,这会弄乱转换矩阵,并且 Sprite 将永远不会显示出来。仅在非空 Sprite 上设置宽度,高度或比例X/Y。

关于actionscript-3 - AS3设置Sprite容器的宽度和高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5134347/

相关文章:

flash - 在 actionscript 3 (flash pro CS5.5) 中运行 hello world 应用程序

flash - Flash中如何获取对象的宽高?

flash - 如何为移动设备(主要是 iOS)制作可滚动的 UI In Touch Flash CS5

apache-flex - 如何在ActionScript 3.0中找到关联数组的长度?

apache-flex - 使用 MP4 编码在 Flash 中流式传输网络摄像头视频

actionscript-3 - 重置属性集合或创建新实例是否更快?

css - Dreamweaver CS5-CSS代码下的错误行

apache-flex - 弹性 : DeepCopy of FileReference

flash - 删除Flash 9中的右键菜单

actionscript-3 - Flash CS5 Actionscript 3.0 转到下一帧并播放代码