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");
     }
 }
Exemplo n.º 2
0
 public AsTextField(int width, int height, String text, String fontName, float fontSize, uint color, bool bold)
 {
     mText     = text != null ? text : "";
     mFontSize = fontSize;
     mColor    = color;
     mHAlign   = AsHAlign.CENTER;
     mVAlign   = AsVAlign.CENTER;
     mBorder   = null;
     mKerning  = true;
     mBold     = bold;
     this.setFontName(fontName);
     mHitArea = new AsQuad(width, height);
     mHitArea.setAlpha(0.0f);
     addChild(mHitArea);
     addEventListener(AsEvent.FLATTEN, onFlatten);
 }
Exemplo n.º 3
0
 public AsTextField(int width, int height, String text, String fontName, float fontSize, uint color, bool bold)
 {
     mText = text != null ? text : "";
     mFontSize = fontSize;
     mColor = color;
     mHAlign = AsHAlign.CENTER;
     mVAlign = AsVAlign.CENTER;
     mBorder = null;
     mKerning = true;
     mBold = bold;
     this.setFontName(fontName);
     mHitArea = new AsQuad(width, height);
     mHitArea.setAlpha(0.0f);
     addChild(mHitArea);
     addEventListener(AsEvent.FLATTEN, onFlatten);
 }
        public virtual void setParent(AsDisplayObjectContainer _value)
        {
            AsDisplayObject ancestor = _value;

            while (ancestor != this && ancestor != null)
            {
                ancestor = ancestor.mParent;
            }
            if (ancestor == this)
            {
                throw new AsArgumentError("An object cannot be added as a child to itself or one " + "of its children (or children's children, etc.)");
            }
            else
            {
                mParent = _value;
            }
        }
        private void getChildEventListeners(AsDisplayObject _object, String eventType, AsVector <AsDisplayObject> listeners)
        {
            AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;

            if (_object.hasEventListener(eventType))
            {
                listeners.push(_object);
            }
            if (container != null)
            {
                AsVector <AsDisplayObject> children = container.mChildren;
                int numChildren = (int)(children.getLength());
                int i           = 0;
                for (; i < numChildren; ++i)
                {
                    getChildEventListeners(children[i], eventType, listeners);
                }
            }
        }
Exemplo n.º 6
0
 public virtual void setBorder(bool _value)
 {
     if (_value && mBorder == null)
     {
         mBorder = new AsSprite();
         addChild(mBorder);
         int i = 0;
         for (; i < 4; ++i)
         {
             mBorder.addChild(new AsQuad(1.0f, 1.0f));
         }
         updateBorder();
     }
     else
     {
         if (!_value && mBorder != null)
         {
             mBorder.removeFromParent(true);
             mBorder = null;
         }
     }
 }
        public virtual AsDisplayObject addChildAt(AsDisplayObject child, int index)
        {
            int numChildren = (int)(mChildren.getLength());

            if (index >= 0 && index <= numChildren)
            {
                child.removeFromParent();
                if (index == numChildren)
                {
                    mChildren.push(child);
                }
                else
                {
                    mChildren.splice(index, (uint)(0), child);
                }
                child.setParent(this);
                child.dispatchEventWith(AsEvent.ADDED, true);
                if (getStage() != null)
                {
                    AsDisplayObjectContainer container = child as AsDisplayObjectContainer;
                    if (container != null)
                    {
                        container.broadcastEventWith(AsEvent.ADDED_TO_STAGE);
                    }
                    else
                    {
                        child.dispatchEventWith(AsEvent.ADDED_TO_STAGE);
                    }
                }
                return(child);
            }
            else
            {
                throw new AsRangeError("Invalid child index");
            }
        }
Exemplo n.º 8
0
        private static int compileObject(AsDisplayObject _object, AsVector <AsQuadBatch> quadBatches, int quadBatchID, AsMatrix transformationMatrix, float alpha, String blendMode, bool ignoreCurrentFilter)
        {
            int         i                      = 0;
            AsQuadBatch quadBatch              = null;
            bool        isRootObject           = false;
            float       objectAlpha            = _object.getAlpha();
            AsDisplayObjectContainer container = _object as AsDisplayObjectContainer;
            AsQuad           quad              = _object as AsQuad;
            AsQuadBatch      batch             = _object as AsQuadBatch;
            AsFragmentFilter filter            = _object.getFilter();

            if (quadBatchID == -1)
            {
                isRootObject = true;
                quadBatchID  = 0;
                objectAlpha  = 1.0f;
                blendMode    = _object.getBlendMode();
                if (quadBatches.getLength() == 0)
                {
                    quadBatches.push(new AsQuadBatch());
                }
                else
                {
                    quadBatches[0].reset();
                }
            }
            if (filter != null && !ignoreCurrentFilter)
            {
                if (filter.getMode() == AsFragmentFilterMode.ABOVE)
                {
                    quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
                }
                quadBatchID = compileObject(filter.compile(_object), quadBatches, quadBatchID, transformationMatrix, alpha, blendMode);
                if (filter.getMode() == AsFragmentFilterMode.BELOW)
                {
                    quadBatchID = compileObject(_object, quadBatches, quadBatchID, transformationMatrix, alpha, blendMode, true);
                }
            }
            else
            {
                if (container != null)
                {
                    int      numChildren = container.getNumChildren();
                    AsMatrix childMatrix = new AsMatrix();
                    for (i = 0; i < numChildren; ++i)
                    {
                        AsDisplayObject child        = container.getChildAt(i);
                        bool            childVisible = child.getAlpha() != 0.0f && child.getVisible() && child.getScaleX() != 0.0f && child.getScaleY() != 0.0f;
                        if (childVisible)
                        {
                            String childBlendMode = child.getBlendMode() == AsBlendMode.AUTO ? blendMode : child.getBlendMode();
                            childMatrix.copyFrom(transformationMatrix);
                            AsRenderSupport.transformMatrixForObject(childMatrix, child);
                            quadBatchID = compileObject(child, quadBatches, quadBatchID, childMatrix, alpha * objectAlpha, childBlendMode);
                        }
                    }
                }
                else
                {
                    if (quad != null || batch != null)
                    {
                        AsTexture texture   = null;
                        String    smoothing = null;
                        bool      tinted    = false;
                        int       numQuads  = 0;
                        if (quad != null)
                        {
                            AsImage image = quad as AsImage;
                            texture = image != null?image.getTexture() : null;

                            smoothing = image != null?image.getSmoothing() : null;

                            tinted   = quad.getTinted();
                            numQuads = 1;
                        }
                        else
                        {
                            texture   = batch.mTexture;
                            smoothing = batch.mSmoothing;
                            tinted    = batch.mTinted;
                            numQuads  = batch.mNumQuads;
                        }
                        quadBatch = quadBatches[quadBatchID];
                        if (quadBatch.isStateChange(tinted, alpha * objectAlpha, texture, smoothing, blendMode, numQuads))
                        {
                            quadBatchID++;
                            if (quadBatches.getLength() <= quadBatchID)
                            {
                                quadBatches.push(new AsQuadBatch());
                            }
                            quadBatch = quadBatches[quadBatchID];
                            quadBatch.reset();
                        }
                        if (quad != null)
                        {
                            quadBatch.addQuad(quad, alpha, texture, smoothing, transformationMatrix, blendMode);
                        }
                        else
                        {
                            quadBatch.addQuadBatch(batch, alpha, transformationMatrix, blendMode);
                        }
                    }
                    else
                    {
                        throw new AsError("Unsupported display object: " + AsGlobal.getQualifiedClassName(_object));
                    }
                }
            }
            if (isRootObject)
            {
                for (i = (int)(quadBatches.getLength() - 1); i > quadBatchID; --i)
                {
                    quadBatches.pop().dispose();
                }
            }
            return(quadBatchID);
        }
 public virtual void setParent(AsDisplayObjectContainer _value)
 {
     AsDisplayObject ancestor = _value;
     while(ancestor != this && ancestor != null)
     {
         ancestor = ancestor.mParent;
     }
     if(ancestor == this)
     {
         throw new AsArgumentError("An object cannot be added as a child to itself or one " + "of its children (or children's children, etc.)");
     }
     else
     {
         mParent = _value;
     }
 }
Exemplo n.º 10
0
 public virtual void setBorder(bool _value)
 {
     if(_value && mBorder == null)
     {
         mBorder = new AsSprite();
         addChild(mBorder);
         int i = 0;
         for (; i < 4; ++i)
         {
             mBorder.addChild(new AsQuad(1.0f, 1.0f));
         }
         updateBorder();
     }
     else
     {
         if(!_value && mBorder != null)
         {
             mBorder.removeFromParent(true);
             mBorder = null;
         }
     }
 }