AS3:将对象限制为舞台宽度?

时间:2011-11-27 18:44:55

标签: actionscript-3 box2d

我想根据舞台宽度限制对象的创建。

我的方法如下:

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

如果我这样做了,它就不会工作

for (var i:int = 0; i<(stage.width); i++){  

我做错了什么?

完整代码:

    [SWF(width = 350, height = 600, frameRate = 60)]  
import com.actionsnippet.qbox.*;  
var sim:QuickBox2D = new QuickBox2D(this);  
sim.createStageWalls();  
// make a heavy circle  
sim.addCircle({x:3, y:3, radius:0.4, density:1});  
// create a few platforms  

// make 26 dominoes  
for (var i:int = 0; i<7; i++){  
//End
     sim.addCircle({x:1 + i * 1.5, y:18, radius:0.1, density:0});
     sim.addCircle({x:2 + i * 1.5, y:17, radius:0.1, density:0});
     sim.addCircle({x:1 + i * 1.5, y:16, radius:0.1, density:0});
     sim.addCircle({x:2 + i * 1.5, y:15, radius:0.1, density:0});

//Mid end

      sim.addCircle({x:0 + i * 2, y:14, radius:0.1, density:0});
      sim.addCircle({x:0 + i * 2, y:13, radius:0.1, density:0});
      sim.addCircle({x:0 + i * 2, y:12, radius:0.1, density:0});
      sim.addCircle({x:0 + i * 2, y:11, radius:0.1, density:0});
      sim.addCircle({x:0 + i * 2, y:10, radius:0.1, density:0});

}  
sim.start();  
sim.mouseDrag();  

1 个答案:

答案 0 :(得分:1)

你必须使用stage.stageWidth

解释一下:

  • stage.stageWidth是Flash Player的宽度
  • stage.width是舞台内容的宽度。因此,如果舞台上没有任何内容,stage.width将为0。