一个Sprite容器的AS3设置宽度和高度 [英] AS3 Setting width and height of a Sprite Container

查看:157
本文介绍了一个Sprite容器的AS3设置宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我的心是令人难以置信的在具有这个问题即时通讯。我知道,这似乎是这样一个简单的问题,我不明白为什么我不能数字出来,但没有少,我不能,我已经几乎放弃了。这里的问题:

我有一个精灵容器应该抱一堆缩略图到视频。我能够填充容器中的所有视频和整个作品,但很明显,如果我加了一堆的视频其将超出flash文件的大小,所以我需要添加的UIScrollBar(我做了),现在的滚动条目标被设置到容器中,但心不是让我来滚动和如果即时通讯纠正这是因为不必须的一组高度的容器。于是我试着去设置这个容器的高度,但第二次我尝试设置高度或宽度均匀我所有的缩略图我曾经能够看到都不见了!这是如果大小被设置为0时,它不是我甚至试图将其设置为指定大小只是为了测试并没有什么作为。反正我的继承人code。如果任何人都可以帮帮忙,我真的AP preciate吧!在此先感谢!

 
进口fl.controls.UIScrollBar;

VAR videoList:XMLList中;
VAR numVideos:数字;
VAR current_Video:数= 0;
VAR video_position:数字;
VAR video_paused:布尔;
VAR xmlPlaylist:字符串;

// XML文件设置
VAR playlist_xml:XML;
VAR myLoader:的URLLoader =新的URLLoader();

//播放列表设置
VAR thumb_width:数字;
VAR thumb_height:数字;
VAR thumbs_x:数字;
VAR thumbs_y:数字;
VAR main_container:雪碧;
VAR大拇指:雪碧;
VAR滚动条:的UIScrollBar;

//装载机数据
this.loaderInfo.addEventListener(引发Event.COMPLETE,loaderComplete);
功能loaderComplete(五:事件):无效
{
    VAR myQueryStrings = this.loaderInfo.parameters;
    xmlPlaylist = myQueryStrings.pList;

    myLoader.load(新的URLRequest(xmlPlaylist + +新的日期()的getTime())的uniq =?);
}

myLoader.addEventListener(引发Event.COMPLETE,的processXML);
功能的processXML(五:事件):无效{
    playlist_xml =新的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();
}

功能startPlayer()
{
    makeContainers();
    callThumbs();
    setVideo(current_Video);
}

功能makeContainers():无效
{
    main_container =新的Sprite();
    的addChild(main_container);

    拇指=新的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;
 

这就是问题是:(如果我注释掉这code则显示缩略图)

 
    thumbs.width = thumb_width;
    thumbs.height =(thumb_height + 11)* 3;
 

 
    thumbs.buttonMode =真;
    main_container.addChild(大拇指);

    滚动条=新的UIScrollBar();
    scrollbar.x = thumbs_x + thumb_width + 2;
    scrollbar.y = thumbs_y;
    scrollbar.setSize(25,(thumb_height + 11)* 3);
    scrollbar.visible = TRUE;
    scrollbar.scrollTarget =大拇指;
    main_container.addChild(滚动);
}

功能callThumbs():无效
{
    对于(VAR我:数量= 0; I(小于)numVideos;我++)//出于某种原因堆栈溢出的心不是让我把比,所以我刚才输入它的符号少...
    {
        VAR thumb_url = videoList [I] @拇指。
        VAR thumb_loader =新的Loader();
        thumb_loader.name =我;
        thumb_loader.load(新的URLRequest(thumb_url));

        thumb_loader.contentLoaderInfo.addEventListener(引发Event.COMPLETE,thumbLoaded);

        thumb_loader.y =(thumb_height + 11)*我;
    }
}

功能thumbLoaded(五:事件):无效
{
    VAR my_thumb:装载机=装载机(e.target.loader);
    thumbs.addChild(my_thumb);
}

功能的playVideo(E:MouseEvent)方法:无效
{
    setVideo(e.target.name);
}

功能onOver(E:MouseEvent)方法:无效
{
    VAR my_thumb:装载机=装载机(e.target);
    my_thumb.alpha = 0.5;
}

功能onOut(E:MouseEvent)方法:无效
{
    VAR my_thumb:装载机=装载机(e.target);
    my_thumb.alpha = 1;
}

功能setVideo(current_Video)
{
    VAR显示:字符串= videoList [current_Video] // @称号;
    VAR视频:字符串= videoList [current_Video] @网址;

    txt_Display.text =显示;
    flvPlayer.source =视频;
}

停止();
 

解决方案

这是很容易。您正在创建雪碧,加听众,设定坐标。精灵仍然是空的。然后,设置宽度和高度,这是翻译成的scaleX和scaleY。在空的Sprite这个食堂变换矩阵和精灵永远不会出现。设置宽度,高度,或将scaleX / Y仅在非空的精灵。

Ok, my mind is boggling over this issue im having. I know this might seem like such an easy issue and I can't understand why I cant figure it out but none the less I can't and I've just about given up. Here's the issue:

I have a sprite container which is supposed to hold a bunch of thumbnails to videos. I am able to populate the container with all the videos and the whole works but obviously if I add a bunch of videos its going to exceed the size of the flash document so I need to add a UIScrollBar (which I did) now the scrollbars target is set to the container but isnt allowing me to scroll and if im correct this is because the container doesnt have a set height. So Im trying to set the height of this container but the second I try setting the height or even width all my thumbnails I used to be able to see are gone! It's as if the size is being set to 0 when its not I've even tried to set it to a specified size just to test and nothing. Anyways heres my code if anyone can help out I'd really appreciate it! Thanks in advance!


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;

This is where the Issue is: (If i comment out this code it displays the thumbnails)


    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();

解决方案

This is easy. You are creating Sprite, adding listeners, setting coordinates. The sprite is still empty. Then you set width and height, which are translating to scaleX and scaleY. On empty sprite this messes up transformation matrix and sprite will never show up. Set width, height, or scaleX/Y only on non-empty sprites.

这篇关于一个Sprite容器的AS3设置宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆