public virtual AsDisplayObject removeChildAt(int index, bool dispose) { if (index >= 0 && index < getNumChildren()) { AsDisplayObject child = mChildren[index]; child.dispatchEventWith(AsEvent.REMOVED, true); if (getStage() != null) { AsDisplayObjectContainer container = child as AsDisplayObjectContainer; if (container != null) { container.broadcastEventWith(AsEvent.REMOVED_FROM_STAGE); } else { child.dispatchEventWith(AsEvent.REMOVED_FROM_STAGE); } } child.setParent(null); index = mChildren.indexOf(child); if (index >= 0) { mChildren.splice(index, (uint)(1)); } if (dispose) { child.dispose(); } return(child); } else { throw new AsRangeError("Invalid child index"); } }
public virtual void _add(AsIAnimatable _object) { if (_object != null && mObjects.indexOf(_object) == -1) { mObjects.push(_object); AsEventDispatcher dispatcher = _object as AsEventDispatcher; if (dispatcher != null) { dispatcher.addEventListener(AsEvent.REMOVE_FROM_JUGGLER, onRemove); } } }
private void processTap(AsTouch touch) { AsTouch nearbyTap = null; float minSqDist = MULTITAP_DISTANCE * MULTITAP_DISTANCE; AsVector <AsTouch> __taps_ = mLastTaps; if (__taps_ != null) { foreach (AsTouch tap in __taps_) { float sqDist = AsMath.pow(tap.getGlobalX() - touch.getGlobalX(), 2) + AsMath.pow(tap.getGlobalY() - touch.getGlobalY(), 2); if (sqDist <= minSqDist) { nearbyTap = tap; break; } } } if (nearbyTap != null) { touch.setTapCount(nearbyTap.getTapCount() + 1); mLastTaps.splice(mLastTaps.indexOf(nearbyTap), (uint)(1)); } else { touch.setTapCount(1); } mLastTaps.push(touch.clone()); }
public virtual void addEventListener(String type, AsEventListenerCallback listener) { if (mEventListeners == null) { mEventListeners = new AsDictionary(); } AsVector <AsEventListenerCallback> listeners = mEventListeners[type] as AsVector <AsEventListenerCallback>; if (listeners == null) { mEventListeners[type] = new AsVector <AsEventListenerCallback>(); } else { if (listeners.indexOf(listener) == -1) { listeners.push(listener); } } }
public virtual void dispatch(AsVector <AsEventDispatcher> chain) { if (chain != null && chain.getLength() != 0) { int chainLength = (int)(getBubbles() ? chain.getLength() : 1); AsEventDispatcher previousTarget = getTarget(); setTarget(chain[0] as AsEventDispatcher); int i = 0; for (; i < chainLength; ++i) { AsEventDispatcher chainElement = chain[i] as AsEventDispatcher; if (mVisitedObjects.indexOf(chainElement) == -1) { bool stopPropagation = chainElement.invokeEvent(this); mVisitedObjects.push(chainElement); if (stopPropagation) { break; } } } setTarget(previousTarget); } }
public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix) { if (resultMatrix != null) { resultMatrix.identity(); } else { resultMatrix = new AsMatrix(); } AsDisplayObject currentObject = this; if (targetSpace == this) { return(resultMatrix); } else { if (targetSpace == mParent || (targetSpace == null && mParent == null)) { if (mPivotX != 0.0f || mPivotY != 0.0f) { resultMatrix.translate(-mPivotX, -mPivotY); } if (mScaleX != 1.0f || mScaleY != 1.0f) { resultMatrix.scale(mScaleX, mScaleY); } if (mRotation != 0.0f) { resultMatrix.rotate(AsMathHelper.toRadians(mRotation)); } if (mX != 0.0f || mY != 0.0f) { resultMatrix.translate(mX, mY); } return(resultMatrix); } else { if (targetSpace == null) { currentObject = this; while (currentObject != null) { currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix); resultMatrix.concat(sHelperMatrix); currentObject = currentObject.getParent(); } return(resultMatrix); } else { if (targetSpace.mParent == this) { targetSpace.getTransformationMatrix(this, resultMatrix); resultMatrix.invert(); return(resultMatrix); } } } } sAncestors.setLength(0); AsDisplayObject commonParent = null; while (currentObject != null) { sAncestors.push(currentObject); currentObject = currentObject.getParent(); } currentObject = targetSpace; while (currentObject != null && sAncestors.indexOf(currentObject) == -1) { currentObject = currentObject.getParent(); } if (currentObject == null) { throw new AsArgumentError("Object not connected to target"); } else { commonParent = currentObject; } currentObject = this; while (currentObject != commonParent) { currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix); resultMatrix.concat(sHelperMatrix); currentObject = currentObject.getParent(); } sTargetMatrix.identity(); currentObject = targetSpace; while (currentObject != commonParent) { currentObject.getTransformationMatrix(currentObject.mParent, sHelperMatrix); sTargetMatrix.concat(sHelperMatrix); currentObject = currentObject.getParent(); } sTargetMatrix.invert(); resultMatrix.concat(sTargetMatrix); return(resultMatrix); }
public virtual void advanceTime(float passedTime) { int i = 0; int touchID = 0; AsTouch touch = null; mElapsedTime = mElapsedTime + passedTime; if (mLastTaps.getLength() > 0) { for (i = (int)(mLastTaps.getLength() - 1); i >= 0; --i) { if (mElapsedTime - mLastTaps[i].getTimestamp() > MULTITAP_TIME) { mLastTaps.splice(i, (uint)(1)); } } } while (mQueue.getLength() > 0) { sProcessedTouchIDs.setLength(sHoveringTouchData.setLength(0)); AsVector <AsTouch> __touchs_ = mCurrentTouches; if (__touchs_ != null) { foreach (AsTouch touch in __touchs_) { if (touch.getPhase() == AsTouchPhase.BEGAN || touch.getPhase() == AsTouchPhase.MOVED) { touch.setPhase(AsTouchPhase.STATIONARY); } } } while (mQueue.getLength() > 0 && sProcessedTouchIDs.indexOf(mQueue[mQueue.getLength() - 1][0]) == -1) { AsArray touchArgs = mQueue.pop(); touch = getCurrentTouch(touchID); if (touch != null && touch.getPhase() == AsTouchPhase.HOVER && touch.getTarget() != null) { sHoveringTouchData.push((As_AS_REST)(AsObject.createLiteralObject("touch", touch, "target", touch.getTarget()))); } this.(int)(touchArgs[0]), (String)(touchArgs[1]), (float)(touchArgs[2]), (float)(touchArgs[3]), (float)(touchArgs[4]), (float)(touchArgs[5]), (float)(touchArgs[6]); sProcessedTouchIDs.push(touchID); } AsTouchEvent touchEvent = new AsTouchEvent(AsTouchEvent.TOUCH, mCurrentTouches, mShiftDown, mCtrlDown); AsVector <Object> __touchDatas_ = sHoveringTouchData; if (__touchDatas_ != null) { foreach (Object touchData in __touchDatas_) { if (((AsObject)(((AsObject)(touchData)).getOwnProperty("touch"))).getOwnProperty("target") != ((AsObject)(touchData)).getOwnProperty("target")) { touchEvent.dispatch(getBubbleChain((AsDisplayObject)(((AsObject)(touchData)).getOwnProperty("target")), sBubbleChain)); } } } AsVector <int> __touchIDs_ = sProcessedTouchIDs; if (__touchIDs_ != null) { foreach (int touchID in __touchIDs_) { getCurrentTouch(touchID).dispatchEvent(touchEvent); } } for (i = (int)(mCurrentTouches.getLength() - 1); i >= 0; --i) { if (mCurrentTouches[i].getPhase() == AsTouchPhase.ENDED) { mCurrentTouches.splice(i, (uint)(1)); } } } sBubbleChain.setLength(0); }
public virtual int getChildIndex(AsDisplayObject child) { return(mChildren.indexOf(child)); }
public virtual AsMatrix getTransformationMatrix(AsDisplayObject targetSpace, AsMatrix resultMatrix) { AsDisplayObject commonParent = null; AsDisplayObject currentObject = null; if (resultMatrix != null) { resultMatrix.identity(); } else { resultMatrix = new AsMatrix(); } if (targetSpace == this) { return(resultMatrix); } else { if (targetSpace == mParent || (targetSpace == null && mParent == null)) { resultMatrix.copyFrom(getTransformationMatrix()); return(resultMatrix); } else { if (targetSpace == null || targetSpace == get_base()) { currentObject = this; while (currentObject != targetSpace) { resultMatrix.concat(currentObject.getTransformationMatrix()); currentObject = currentObject.mParent; } return(resultMatrix); } else { if (targetSpace.mParent == this) { targetSpace.getTransformationMatrix(this, resultMatrix); resultMatrix.invert(); return(resultMatrix); } } } } commonParent = null; currentObject = this; while (currentObject != null) { sAncestors.push(currentObject); currentObject = currentObject.mParent; } currentObject = targetSpace; while (currentObject != null && sAncestors.indexOf(currentObject) == -1) { currentObject = currentObject.mParent; } sAncestors.setLength(0); if (currentObject != null) { commonParent = currentObject; } else { throw new AsArgumentError("Object not connected to target"); } currentObject = this; while (currentObject != commonParent) { resultMatrix.concat(currentObject.getTransformationMatrix()); currentObject = currentObject.mParent; } if (commonParent == targetSpace) { return(resultMatrix); } sHelperMatrix.identity(); currentObject = targetSpace; while (currentObject != commonParent) { sHelperMatrix.concat(currentObject.getTransformationMatrix()); currentObject = currentObject.mParent; } sHelperMatrix.invert(); resultMatrix.concat(sHelperMatrix); return(resultMatrix); }