Actionscript 3 as3 hitTestObject类对象命中类
我试图加载多个气泡,并让它们在屏幕上反弹。如果他们互相攻击,他们应该从我的代码中做些什么 以下是不起作用的代码:Actionscript 3 as3 hitTestObject类对象命中类,actionscript-3,Actionscript 3,我试图加载多个气泡,并让它们在屏幕上反弹。如果他们互相攻击,他们应该从我的代码中做些什么 以下是不起作用的代码: if(e.target.hitTestObject(e.target.getChildAt(1))) { trace("Items hit");// Runs on every enter frame. Should not. } 这是我的主要时间表:numberPop.as package {
if(e.target.hitTestObject(e.target.getChildAt(1)))
{
trace("Items hit");// Runs on every enter frame. Should not.
}
这是我的主要时间表:numberPop.as
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.system.Capabilities;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.system.Capabilities;
import flash.display.StageDisplayState;
// Greensock Annimation
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import com.greensock.plugins.TransformAroundCenterPlugin;
TweenPlugin.activate([TransformAroundCenterPlugin]);
TweenPlugin.activate([TransformAroundPointPlugin]);
import com.greensock.plugins.CacheAsBitmapPlugin;
import com.theBubble;
public class numberPop extends MovieClip
{
public var numberBubble:theBubble;
///screen rez
public static var _screenX:int;
public static var _screenY:int;
public var Desktop:Boolean;
public var iPhone:Boolean;
public var i:Number = 2;
public var Jesus:Array = new Array('3','4');
public function numberPop()
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
setStage(null);
//addBubble(3);
TweenMax.delayedCall(1, addBubble);
TweenMax.delayedCall(3, addBubble);
}
public function addBubble()
{
numberBubble = new theBubble(i,this);
addChild(numberBubble);
numberBubble.name = ""+i+"";
trace("I here " + numberBubble.name);
i++;
}
public function setStage(e:Event)
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
if (flash.system.Capabilities.screenResolutionX > stage.fullScreenWidth)
{
_screenX = stage.fullScreenWidth;
_screenY = stage.fullScreenHeight;
//Rez = "Screen Height";
trace("Second: " + _screenY);
}
else
{
if(iPhone)
{
_screenX = flash.system.Capabilities.screenResolutionY;
_screenY = flash.system.Capabilities.screenResolutionX;
}
else
{
_screenX = flash.system.Capabilities.screenResolutionX;
_screenY = flash.system.Capabilities.screenResolutionY;
}
trace("Second: " + _screenY);
}
// _screenX = stage.stageWidth;
//_screenY = stage.stageHeight;
}
//////////////////////////
//////////////////////////
}
}
这是我的课
package com {
import flash.display.MovieClip;
import flash.events.*;
import flash.system.Capabilities;
import flash.display.StageDisplayState;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.system.Capabilities;
import flash.display.StageDisplayState;
// Greensock Annimation
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import com.greensock.plugins.TransformAroundCenterPlugin;
TweenPlugin.activate([TransformAroundCenterPlugin]);
TweenPlugin.activate([TransformAroundPointPlugin]);
import com.greensock.plugins.CacheAsBitmapPlugin;
public class theBubble extends MovieClip
{
public var num:Number;
public var _screenX:Number;
public var _screenY:Number;
public var xDie:Boolean = true;
public var yDie:Boolean = true;
public var Main:MovieClip;
public function theBubble(num:Number,mc:MovieClip)
{
super();
this.num = num;
trace("Number is: " + num);
Main = mc;
this.Number_text.text = "" + num + "";
this.addEventListener(MouseEvent.CLICK, bubbleAction);
this.addEventListener(Event.ENTER_FRAME, checkHit);
trace(Main);
}
public function checkHit(e:Event)
{
if(e.target.hitTestObject(e.target.getChildAt(1)))
{
trace("Items hit");
}
var xVal = 5;
var yVal = 5;
if(xDie)
{
this.x = this.x + xVal;
}
else
{
this.x = this.x - xVal;
}
if(this.x >= numberPop._screenX - this.width)
{
xDie = false;
}
if(this.x <= 0)
{
xDie = true;
}
///////
if(yDie)
{
this.y = this.y + yVal;
}
else
{
this.y = this.y - yVal;
}
if(this.y >= numberPop._screenY - this.height)
{
yDie = false;
}
if(this.y <= 0)
{
yDie = true;
}
}
public function bubbleAction(e:Event)
{
trace(this.name);
}
}
}
e、 target.getChildAt1是e.target的子级,因此它将始终命中。你会想以某种方式将冒泡和你正在测试的东西分开。ife.target.hitTestObjecte.target.getChildAt1-因此e.target是冒泡,而e.target.getChildAt1是冒泡的子对象,所以它总是会命中,不是吗?我知道有点晚了,但是像Manager这样的类应该使用组合*