Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flash/Actionscript之间不平滑_Flash_Actionscript 3_Actionscript_Tweener - Fatal编程技术网

Flash/Actionscript之间不平滑

Flash/Actionscript之间不平滑,flash,actionscript-3,actionscript,tweener,Flash,Actionscript 3,Actionscript,Tweener,我使用Flash-ActionScript3.0从XML文件加载图像路径(最终是图像),然后使用Tweener类设置Tweenes的动画,以便在标题上滚动 问题是:卷轴不平滑,起伏很大,我不知道为什么 我在网上读到,启用位图平滑有帮助,但我不知道如何使用从XML加载的图像 如果你需要代码,我可以发布它,但它相当长,所以我想如果有人能想出一些常见的原因,我不会一开始就这样。您可以在我们的一个页面上查看滚动条,例如 谢谢 编辑:请求代码 import fl.transitions.Tween; i

我使用Flash-ActionScript3.0从XML文件加载图像路径(最终是图像),然后使用Tweener类设置Tweenes的动画,以便在标题上滚动

问题是:卷轴不平滑,起伏很大,我不知道为什么

我在网上读到,启用位图平滑有帮助,但我不知道如何使用从XML加载的图像

如果你需要代码,我可以发布它,但它相当长,所以我想如果有人能想出一些常见的原因,我不会一开始就这样。您可以在我们的一个页面上查看滚动条,例如

谢谢

编辑:请求代码

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import caurina.transitions.*

var imageLoader:Loader;
var currentLoader:Loader;
var xml:XML;
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
var xmlLoader2:URLLoader = new URLLoader();
var k:int;
var iterator:int = 0;
var imageCount:int;

//********** Begin editable region *************///
//---------------------------------------------
//dont change startX unless you are sure -> 
//start coordinates are affected by more than this variable
var startX:Number = 690;
//change endX to extend the scroll length
var endX:Number = 20;
//change scrollSpeed to change speed of images
var scrollSpeed:Number = 32;
//---------------------------------------------
//********** End editable region **************///

var ratio:Number = scrollSpeed/(startX-endX);
var rate:Number = (startX-endX)/scrollSpeed;

//align tabs under heading
setChildIndex(headertab,1);

// ----- Program Main ----- //
initializeMouseEvents();
Main_Begin();

//@ initializes mouse events for url navigation
function initializeMouseEvents():void
{
Mouse.cursor = flash.ui.MouseCursor.BUTTON
headertab.addEventListener(MouseEvent.ROLL_OVER, expandTab);
headertab.addEventListener(MouseEvent.ROLL_OUT, shrinkTab);
function expandTab(e:MouseEvent):void
{
    Tweener.addTween(headertab, {y:5, time:.1, delay:0, transition:"linear"});
}
function shrinkTab(e:MouseEvent):void
{
    Tweener.addTween(headertab, {y:0, time:.1, delay:0, transition:"linear"});
}
stage.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
    navigateToURL(new URLRequest("http://www.greencupboards.com"), "_blank");
}
}

function Main_Begin():void
{
xmlLoader.load(new URLRequest("http://www.greencupboards.com/media/community/scroll/images.xml"));
xmlLoader.addEventListener(Event.COMPLETE, loadInitialXml);

function loadInitialXml(event:Event):void
{
    xml = XML(event.target.data);
    xmlList = xml.children();
    imageCount = xmlList.length();
    for(var j:int = 1; j < 10; j++)
    {
        k = imageCount - j;
        imageLoader = new Loader();
        imageLoader.name = "loader"+j;
        imageLoader.load(new URLRequest(xmlList[k].source));
        imageLoader.x = endX + 60*(j+1) + 10;
        imageLoader.y = 37;
        //imageLoader.addEventListener(MouseEvent.ROLL_OVER, pauseAll);
        //imageLoader.addEventListener(MouseEvent.ROLL_OUT, resumeAll);
        addChild(imageLoader);
        setChildIndex(imageLoader,1);
        //Tweener.addTween(imageLoader, {alpha:1, time:1.4, delay:0, transition:"linear"});
        Tweener.addTween(imageLoader, {x:endX, time:rate*(j+1)/7.2, delay:0, transition:"linear"});
        Tweener.addTween(imageLoader, {alpha:0, time:2, delay:(rate*(j+1)/7.5)-4, transition:"linear"});
        imageLoader.unload();
    }

    //first scrolling images to fade in
    loadXML();
    //loop of scrolling images infinetely
    function loop():void 
    {
        loadXML();
    }
    setInterval(loop,(  ((imageCount*60))/rate)*1000   );

//imageLoader.name = xmlList[i].attribute("source");
}
}

function loadXML()
{
xmlLoader2.load(new URLRequest("http://www.greencupboards.com/media/community/scroll/images.xml"));
xmlLoader2.addEventListener(Event.COMPLETE, xmlLoaded);

function xmlLoaded(event:Event):void
{
    xml = XML(event.target.data);
    xmlList = xml.children();
    imageCount = xmlList.length();
    for(var i:int = 0; i < xmlList.length(); i++)
    {
        imageLoader = new Loader();
        imageLoader.name = "loader"+i;
        imageLoader.load(new URLRequest(xmlList[i].source));
        imageLoader.x = startX + 60*i;
        imageLoader.y = 37;
        imageLoader.alpha = -1;
        //imageLoader.addEventListener(MouseEvent.ROLL_OVER, pauseAll);
        //imageLoader.addEventListener(MouseEvent.ROLL_OUT, resumeAll);
        addChild(imageLoader);
        setChildIndex(imageLoader,1);
        makeTween(imageLoader);
        iterator++;
    }
iterator = 0;
//imageLoader.name = xmlList[i].attribute("source");
}
}

function resumeAll(event:Event):void
{
    Tweener.resumeAllTweens();
}

function pauseAll(event:Event):void
{
    Tweener.pauseAllTweens();
}

function makeTween(obj:Loader):void
{
Tweener.addTween(obj, {alpha:1, time:2, delay:60*ratio*iterator+3.3, transition:"linear"});
Tweener.addTween(obj, {x:endX, time:(scrollSpeed + 60*ratio*iterator), delay:0, transition:"linear", onComplete:unloadObject(obj)});
}

function unloadObject(obj:Object):void
{
//iterator - 2 simply creates a big enough delay.  I think the scroll gets ahead of fadeout so it needs this buffer to run many times
Tweener.addTween(obj, {alpha:0, time:2, delay:(scrollSpeed + 60*ratio*(iterator-2)), transition:"linear"});
obj.unload();
}
导入fl.transitions.Tween;
导入fl.transitions.easing.*;
导入fl.transitions.TweenEvent;
导入caurina.transitions*
var-imageLoader:Loader;
var-currentLoader:Loader;
var-xml:xml;
var-xmlList:xmlList;
var xmlLoader:URLLoader=新的URLLoader();
var xmlLoader2:URLLoader=新的URLLoader();
var k:int;
变量迭代器:int=0;
var-imageCount:int;
//**********开始可编辑区域*************///
//---------------------------------------------
//除非您确定->
//起始坐标受此变量影响的范围不止此
var startX:编号=690;
//更改endX以延长滚动长度
var endX:数值=20;
//更改滚动速度以更改图像的速度
变量滚动速度:数字=32;
//---------------------------------------------
//**********结束可编辑区域**************///
var比率:数字=滚动速度/(startX endX);
变化率:数字=(startX endX)/滚动速度;
//对齐标题下的选项卡
setChildIndex(headertab,1);
//-----程序主------//
initializeMouseEvents();
Main_Begin();
//@初始化url导航的鼠标事件
函数initializeMouseEvents():void
{
Mouse.cursor=flash.ui.MouseCursor.BUTTON
headertab.addEventListener(MouseEvent.ROLL_OVER,expandTab);
headertab.addEventListener(MouseEvent.ROLL_OUT,shrinkTab);
函数expandTab(e:MouseeEvent):无效
{
addTween(headertab,{y:5,时间:.1,延迟:0,转换:“线性”});
}
函数收缩选项卡(e:MouseeEvent):无效
{
addTween(headertab,{y:0,时间:.1,延迟:0,转换:“线性”});
}
stage.addEventListener(MouseEvent.CLICK,onClick);
函数onClick(e:MouseEvent):void
{
导航URL(新的URL请求(“http://www.greencupboards.com“(空白);
}
}
函数Main_Begin():void
{
加载(新的URL请求(“http://www.greencupboards.com/media/community/scroll/images.xml"));
addEventListener(Event.COMPLETE,loadInitialXml);
函数loadInitialXml(事件:event):void
{
xml=xml(event.target.data);
xmlList=xml.children();
imageCount=xmlList.length();
对于(var j:int=1;j<10;j++)
{
k=图像计数-j;
imageLoader=新加载器();
imageLoader.name=“loader”+j;
load(新的URLRequest(xmlList[k].source));
imageLoader.x=endX+60*(j+1)+10;
imageLoader.y=37;
//imageLoader.addEventListener(MouseEvent.ROLL_OVER,pauseAll);
//imageLoader.addEventListener(MouseEvent.ROLL_OUT,resumeAll);
addChild(imageLoader);
setChildIndex(imageLoader,1);
//addTween(imageLoader,{alpha:1,时间:1.4,延迟:0,转换:“线性”});
addTween(图像加载器,{x:endX,时间:速率*(j+1)/7.2,延迟:0,转换:“线性”});
addTween(imageLoader,{alpha:0,时间:2,延迟:(速率*(j+1)/7.5)-4,转换:“线性”});
imageLoader.unload();
}
//首先滚动图像以淡入
loadXML();
//内滚图像的循环
函数循环():void
{
loadXML();
}
设置间隔(循环,((imageCount*60))/速率)*1000);
//imageLoader.name=xmlList[i]。属性(“源”);
}
}
函数loadXML()
{
加载(新的URL请求(“http://www.greencupboards.com/media/community/scroll/images.xml"));
xmlLoader2.addEventListener(Event.COMPLETE,xmlLoaded);
函数xmlLoaded(事件:事件):void
{
xml=xml(event.target.data);
xmlList=xml.children();
imageCount=xmlList.length();
for(var i:int=0;i
更新

不要直接将加载程序添加到后台。(在我看来,这是一个糟糕的做法)

而是这样做:

imageLoader.loaderInfo.addEventListener ( Event.COMPLETE, handleLoadComplete );
原创

以下是平滑位图的方法:

private function handleLoadComplete ( e : Event ) : void
{
    imageLoader.loaderInfo.removeEventListener( Event.COMPLETE, handleLoadComplete );
    var bitmap:Bitmap = Bitmap (loader.content); //get the loaders content as a bitmap
    bitmap.smoothing = true;//turn on smoothing
    location.addChilc ( bitmap ) // add the bitmap to you desired location
}
动画之所以起伏,是因为它太慢


提高flash电影的FPS。并提高动画速度。

有时制作动画的更好方法是使用ENTER_FRAME事件手动制作动画

我的
private function handleLoadComplete ( e : Event ) : void
{
    imageLoader.loaderInfo.removeEventListener( Event.COMPLETE, handleLoadComplete );
    var bitmap:Bitmap = Bitmap (loader.content); //get the loaders content as a bitmap
    bitmap.smoothing = true;//turn on smoothing
    location.addChilc ( bitmap ) // add the bitmap to you desired location
}
package 
{
  import flash.display.Sprite;
  import flash.events.Event;

  [SWF(width="400", height="100", frameRate="30", backgroundColor="#FFFFFF")]
  public class Main extends Sprite
  {
    private var items : Array;
    public function Main()
    {
        items = [];
        var curx:int = 0;
        // create some items
        for (var i:int=0;i<10;i++)
        {
            var s:Sprite = new Sprite();
            s.x = curx;
            s.graphics.beginFill(0xff0000*i/10, 1);
            s.graphics.drawRect(0, 0, 20, 40);
            items.push(s);

            addChild(s);
            curx += s.width + 6;
        }
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }

    private function onEnterFrame(event : Event) : void 
    {
        var i:int = items.length-1;
        var s:Sprite;
        while (i >= 0)
        {
            s = items[i] as Sprite;
            if (s.x <= -20) {
                s.x = stage.stageWidth;
            }
            s.x -= 2;
            --i;                
        }
    }
  }
}
private function startAnimation():void
{
    for each(var yourImage:Bitmap in SomeArrayYouCollectTheImagesIn)
    {
        TweenLite.to(yourImage, timeItShouldTake, {x: X-PositionToGoTo, onComplete: someFunction, onCompleteParams: [yourImage]});
    }
}

private function someFunction(image:Bitmap):void
{
    //You can reposition your image here
}

private function stopAnimation(image:Bitmap):void
{
    TweenLite.killTweensOf(image);
}