2011-05-05 25 views
0

最近我一直无法解决Flash CS3的问题。我真的需要一些帮助清除脚本。涉及坐标的条件语句,Adobe Flash

我一直在试图做一个代码的动作,将设置一个功能true如果一个对象被移动到屏幕的特定部分。令人困惑的是,规则适用于特定四个坐标之间的时间(在这种情况下,165和 231作为X坐标,而295和330作为y坐标;“honey”是该符号的实例名称) 。

我最后一次要求帮助,我得到这个代码:

bool IsBetweenInclusive(int value, int lower, int upper) 
{ 
    return value >= lower 
     && value <= upper; 
} 

然而,当我试图把它变成一个条件语句,这是行不通的。我真的需要帮助,并会真正感谢帮助。

+2

该代码不是ActionScript。 – AsTheWormTurns 2011-12-04 16:20:47

回答

0
/** 
    * Whether a point is within a rectangular bounds. 
    * 
    * @param x   Point x-coordinate to be tested. 
    * @param y   Point y-coordinate to be tested. 
    * @param bounds Rectangle boundary to be tested against. 
    * @return   True if point is within bounds. 
    */ 
    public static function withinBounds(x:Number, y:Number, bounds:Rectangle):Boolean 
    { 
     if ((x > bounds.x) && 
      (x < bounds.x + bounds.width) && 
      (y > bounds.y) && 
      (y < bounds.y + bounds.height)) 
      return true; 

     return false; 
    } 
0

您可以使用rectangle,它已经有一个方法。假设你有一个左上点x1,y1和右下角点x2,y2和点x,y要检查:

var area = new Rectangle (x1, y1, x2-x1, y2-y1); 

if(area.contains(x,y)) { /* ... */ } 

还有containsRect如果你需要检查对象是否完全在给定的区域。