Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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
Actionscript 3 我需要让对象圆继续沿着屏幕向下重复,但我';我找不到正确的代码 导入flash.display.MovieClip; 导入flash.events.Event; 公共类电影{ 公共职能(){ //降雨 变量i:int; 对于(i=0;i祝好运! E.Talk.y+=1;尝试如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。 import flash.display.Sprite; import flash.display.Shape; import flash.display.DisplayObject; import flash.events.Event; package{ public class Rainfall extends Sprite {//class names should be title case private var numDrops = 50;//this make it easier to configure private var dropRadius = 20; private var maxY; public function Rainfall() { addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null } private function init(event:Event):void{ maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset var i:int; for (i = 0; i < numDrops; i++){ var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing mc.x = Math.random() * stage.stageWidth ; mc.y = Math.random() * 400 * 4 ; mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1. mc.graphics.beginFill(0x0000FF); mc.graphics.drawCircle(0,0,dropRadius); addChild(mc); } addEventListener(Event.ENTER_FRAME, moveDown) ; } private function moveDown(e:Event):void { //fall speed for(var i:int = 0 ; i < numDrops; i++){ var drop:DisplayObject = getChildAt(i); drop.y += 1 ; if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area) } } } }_Actionscript 3_Loops - Fatal编程技术网

Actionscript 3 我需要让对象圆继续沿着屏幕向下重复,但我';我找不到正确的代码 导入flash.display.MovieClip; 导入flash.events.Event; 公共类电影{ 公共职能(){ //降雨 变量i:int; 对于(i=0;i祝好运! E.Talk.y+=1;尝试如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。 import flash.display.Sprite; import flash.display.Shape; import flash.display.DisplayObject; import flash.events.Event; package{ public class Rainfall extends Sprite {//class names should be title case private var numDrops = 50;//this make it easier to configure private var dropRadius = 20; private var maxY; public function Rainfall() { addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null } private function init(event:Event):void{ maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset var i:int; for (i = 0; i < numDrops; i++){ var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing mc.x = Math.random() * stage.stageWidth ; mc.y = Math.random() * 400 * 4 ; mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1. mc.graphics.beginFill(0x0000FF); mc.graphics.drawCircle(0,0,dropRadius); addChild(mc); } addEventListener(Event.ENTER_FRAME, moveDown) ; } private function moveDown(e:Event):void { //fall speed for(var i:int = 0 ; i < numDrops; i++){ var drop:DisplayObject = getChildAt(i); drop.y += 1 ; if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area) } } } }

Actionscript 3 我需要让对象圆继续沿着屏幕向下重复,但我';我找不到正确的代码 导入flash.display.MovieClip; 导入flash.events.Event; 公共类电影{ 公共职能(){ //降雨 变量i:int; 对于(i=0;i祝好运! E.Talk.y+=1;尝试如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。 import flash.display.Sprite; import flash.display.Shape; import flash.display.DisplayObject; import flash.events.Event; package{ public class Rainfall extends Sprite {//class names should be title case private var numDrops = 50;//this make it easier to configure private var dropRadius = 20; private var maxY; public function Rainfall() { addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null } private function init(event:Event):void{ maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset var i:int; for (i = 0; i < numDrops; i++){ var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing mc.x = Math.random() * stage.stageWidth ; mc.y = Math.random() * 400 * 4 ; mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1. mc.graphics.beginFill(0x0000FF); mc.graphics.drawCircle(0,0,dropRadius); addChild(mc); } addEventListener(Event.ENTER_FRAME, moveDown) ; } private function moveDown(e:Event):void { //fall speed for(var i:int = 0 ; i < numDrops; i++){ var drop:DisplayObject = getChildAt(i); drop.y += 1 ; if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area) } } } },actionscript-3,loops,Actionscript 3,Loops,我对ActionScript3还相当陌生,但在想如何让圆圈在屏幕上连续循环时遇到了很多麻烦,但关于我做错了什么或我需要让它循环什么的任何提示都会抛出尝试以下方法: import flash.display.MovieClip; import flash.events.Event; public class rainfall extends MovieClip { public function rainfall() { // rainfall

我对ActionScript3还相当陌生,但在想如何让圆圈在屏幕上连续循环时遇到了很多麻烦,但关于我做错了什么或我需要让它循环什么的任何提示都会抛出

尝试以下方法:

import flash.display.MovieClip;
import flash.events.Event; 


public class rainfall extends MovieClip {


    public function rainfall() {
        // rainfall



        var i:int;
        for (i = 0; i< 50; i++)

        {  
           //variables
            var mc:MovieClip = new MovieClip ();



                //theStage, and alpha properties
                mc.x  = Math.random() * stage.stageWidth ;
                mc.y = Math.random() * 400 * 4 ;
                mc.alpha = Math.random()* 2;
            mc.graphics.beginFill(0x0000FF);
            mc.graphics.drawCircle(0,0,20);
                //trace
                trace(i);


            addChild(mc);
            mc.addEventListener(Event.ENTER_FRAME, moveDown) ;
        }

                    function moveDown(e:Event):void
                { //fall speed
                        e.target.y += 1 ;
                }

            }
导入flash.display.Sprite;
导入flash.display.Shape;
导入flash.display.DisplayObject;
导入flash.events.Event;
包装{
公共类Sprite{//类名称应为标题大小写
private var numDrops=50;//这使配置更容易
专用var dropRadius=20;
私有var-maxY;
公共职能(){
addEventListener(Event.ADDED_TO_STAGE,init);//确保STAGE属性不为null
}
私有函数init(事件:event):void{
maxY=stage.stageHeight;//getter可能很慢,请存储高度,以便在每次放置重置时重复使用
变量i:int;
对于(i=0;imaxY)drop.y=-dropRadius;//如果水滴向下退出屏幕,则将其放回顶部(可见区域上方)
}
}
}
}
它不是经过测试的代码,因此您可能会遇到语法错误,但这些想法已被注释:

您需要为您的问题使用一个条件:如果水滴的垂直位置大于舞台的高度,那么水滴的垂直位置应该重置回舞台的顶部(`if(drop.y>maxY)drop.y=-dropRadius;a)

虽然在刚开始使用flash时没有必要,但以下是一些有关使用flash时效率/速度的提示:

  • MovieClip是一个动态类(您可以动态地向实例添加属性),但也有成本。因为您只需要渲染/绘制元素,不需要事件或子元素,这使您的圆成为使用Shape类的完美候选对象。此外,您的主类可以是精灵,因为您不使用时间线
  • 在actionscript中,getter和setter可能有点慢。缓存/存储不会随时间发生太大变化的值是一种健康的习惯,可以作为本地变量重新使用,以便更快地访问
  • 这并不是一个性能问题:一个常见的陷阱是没有在显示对象上初始化stage,这会导致一个恼人的、对初学者来说令人费解的空对象引用错误。如果在显示对象(Shape/Sprite/MovieClip)上使用stage属性,最好确保它已添加到stage中(并且stage属性不为null)使用
    ADDED_TO_stage
    事件

  • <> P>祝好运!

    <代码> E.Talk.y+=1;尝试<代码>如果(E.Task.y> Point,StaleHead)E.Trase.y=0;,因此简短地查看条件。也考虑使用一个单帧监听器并循环通过显示列表(例如:<代码>为(var i:int=0;i < NoMeStudio;I++)/ < < /代码>)@GeorgeProfenza,我想你应该把它作为一个答案。
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.DisplayObject;
    import flash.events.Event; 
    
    
    package{
    
        public class Rainfall extends Sprite {//class names should be title case
    
            private var numDrops = 50;//this make it easier to configure
            private var dropRadius = 20;
            private var maxY;
    
            public function Rainfall() {
                addEventListener(Event.ADDED_TO_STAGE,init);//make sure the stage property will not be null
            }
    
            private function init(event:Event):void{
                maxY = stage.stageHeight;//getters can be slow, store the height so it can be reused for each drop reset
                var i:int;
                for (i = 0; i < numDrops; i++){  
                   var mc:Shape = new Shape();//if no interactivity is needed, Shape is the simplest/lightest class to use for drawing
                    mc.x  = Math.random() * stage.stageWidth ;
                    mc.y = Math.random() * 400 * 4 ;
                    mc.alpha = 0.1 + Math.random() * 0.9;//alpha values are from 0 to 1.
                    mc.graphics.beginFill(0x0000FF);
                    mc.graphics.drawCircle(0,0,dropRadius);
                    addChild(mc);
                }
                addEventListener(Event.ENTER_FRAME, moveDown) ;
            }
            private function moveDown(e:Event):void
            { //fall speed
                for(var i:int = 0 ; i < numDrops; i++){
                    var drop:DisplayObject = getChildAt(i);
                    drop.y += 1 ;
                    if(drop.y > maxY) drop.y = -dropRadius;//if the drop exits the screen downards, place it back at the top (above the visible area)
                }
            }
    
        }
    
    }