自定义 Flex/ActionScript UIComponent 在调整大小期间不断被绘制多次

发布于 2024-10-03 02:07:31 字数 3150 浏览 4 评论 0原文

我创建了一个自定义 uiComponent ,每当调整浏览器或其特定容器的大小时,就会发生重新绘制,但组件的内容会一次又一次地绘制...... 因此,如果我移动容器,我最终会在彼此的顶部绘制多个圆圈,但会根据重绘发生时容器所在的位置进行偏移。 我的 updateDisplayList 代码如下。 我是否需要进行某种清除,以便它不会像这样不断重复??? 非常感谢您的帮助!

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

            super.updateDisplayList(unscaledWidth, unscaledHeight);                             

            trace("height: " + parent.height);
            trace("width: " + parent.width);

            if (parent.height <= parent.width) {
                radius = Math.round((parent.height*.95)/2);
            }
            else {
                radius = Math.round((parent.width*.95)/2);
            }

            trace("radius: " + radius);

            outterRadius = Math.round(radius*.70);
            innerRadius = Math.round(radius*.30);

            trace("outterradius: " + outterRadius); 
            trace("innerradius: " + innerRadius);

            centerX = this.width/2;
            centerY = this.height/2;

            trace("centerX: " + centerX);
            trace("centerY: " + centerY);

            var innerCircle:Sprite = new Sprite();
            var outterCircle:Sprite = new Sprite();
            var baseCircle:Sprite = new Sprite();

            baseCircle.graphics.beginFill(0x000000);
            baseCircle.graphics.drawCircle(centerX, centerY, radius);               

            outterCircle.graphics.lineStyle(2, 0xA10303, .75);
            outterCircle.graphics.drawCircle(centerX, centerY, outterRadius);


            innerCircle.graphics.lineStyle(2, 0xA10303, .75);
            innerCircle.graphics.drawCircle(centerX, centerY, innerRadius);

            addChild(baseCircle);   
            addChild(outterCircle);
            addChild(innerCircle);

            for (var bubbleCount:int=0; bubbleCount < bubbleList.length; bubbleCount++) {
                var globalPoint:Point = this.localToGlobal(getPointInCircle(radius));
                var radarBubble:RadarBubble = bubbleList.getItemAt(bubbleCount) as RadarBubble;
                var bubbleLocalPoint:Point = radarBubble.globalToLocal(globalPoint);
                radarBubble.x = bubbleLocalPoint.x;
                radarBubble.y = bubbleLocalPoint.y;
                trace("Add bubble: " + radarBubble.x + ", " + radarBubble.y + ", " + radarBubble.radius);
                addChild(radarBubble);                                      
            }                           

            // create radar display lines to be animated
            for (var angleCount:int=0; angleCount < 360; angleCount++) {
                var tmpLine3:Sprite = new Sprite();
                tmpLine3.graphics.lineStyle(2, 0xA10303, 1);
                tmpLine3.graphics.moveTo(centerX, centerY);                                         
                tmpLine3.graphics.lineTo(getEndpoint(angleCount).x, getEndpoint(angleCount).y);
                tmpLine3.visible = false;
                addChild(tmpLine3);
                lineCollection.addItemAt(tmpLine3, angleCount);                             
            }

        }

I've created a custom uicomponent and whenever the browser or its specific container is resized, a repaint occurs but the contents of the component get drawn again and again and again...
So, if I move the container I'll end up with multiple circles drawn on top of each other but offset depending upon where the container is when the repaint occurs.
My updateDisplayList code is below.
Do I need to do some sort of clear so that it doesn't contiuously getting duplicated like this???
Thanks so much for any help!

    override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

            super.updateDisplayList(unscaledWidth, unscaledHeight);                             

            trace("height: " + parent.height);
            trace("width: " + parent.width);

            if (parent.height <= parent.width) {
                radius = Math.round((parent.height*.95)/2);
            }
            else {
                radius = Math.round((parent.width*.95)/2);
            }

            trace("radius: " + radius);

            outterRadius = Math.round(radius*.70);
            innerRadius = Math.round(radius*.30);

            trace("outterradius: " + outterRadius); 
            trace("innerradius: " + innerRadius);

            centerX = this.width/2;
            centerY = this.height/2;

            trace("centerX: " + centerX);
            trace("centerY: " + centerY);

            var innerCircle:Sprite = new Sprite();
            var outterCircle:Sprite = new Sprite();
            var baseCircle:Sprite = new Sprite();

            baseCircle.graphics.beginFill(0x000000);
            baseCircle.graphics.drawCircle(centerX, centerY, radius);               

            outterCircle.graphics.lineStyle(2, 0xA10303, .75);
            outterCircle.graphics.drawCircle(centerX, centerY, outterRadius);


            innerCircle.graphics.lineStyle(2, 0xA10303, .75);
            innerCircle.graphics.drawCircle(centerX, centerY, innerRadius);

            addChild(baseCircle);   
            addChild(outterCircle);
            addChild(innerCircle);

            for (var bubbleCount:int=0; bubbleCount < bubbleList.length; bubbleCount++) {
                var globalPoint:Point = this.localToGlobal(getPointInCircle(radius));
                var radarBubble:RadarBubble = bubbleList.getItemAt(bubbleCount) as RadarBubble;
                var bubbleLocalPoint:Point = radarBubble.globalToLocal(globalPoint);
                radarBubble.x = bubbleLocalPoint.x;
                radarBubble.y = bubbleLocalPoint.y;
                trace("Add bubble: " + radarBubble.x + ", " + radarBubble.y + ", " + radarBubble.radius);
                addChild(radarBubble);                                      
            }                           

            // create radar display lines to be animated
            for (var angleCount:int=0; angleCount < 360; angleCount++) {
                var tmpLine3:Sprite = new Sprite();
                tmpLine3.graphics.lineStyle(2, 0xA10303, 1);
                tmpLine3.graphics.moveTo(centerX, centerY);                                         
                tmpLine3.graphics.lineTo(getEndpoint(angleCount).x, getEndpoint(angleCount).y);
                tmpLine3.visible = false;
                addChild(tmpLine3);
                lineCollection.addItemAt(tmpLine3, angleCount);                             
            }

        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

去了角落 2024-10-10 02:07:31

阅读 Flex 组件生命周期。很多事情可能会执行 invalidateDisplayList() ,从而导致 updateDisplayList 在下一个渲染事件期间重新执行。

我在这里看到的问题是您每次都创建新的baseCircle、outerCircle 和innerCircle。相反,您应该创建每个实例之一,并在 updateDisplayList() 运行时更新它。

我可能会在当前组件上创建innerCircle、outerCircle 和baseCircle 变量的实例。在 createChildren() 中,您可以将它们添加为组件上的子项。在updateDisplayList中可以进行相关的绘制。

Read up on the Flex component lifecycle. A lot of things may execute invalidateDisplayList() thereby causing updateDisplayList to be re-execute during the next render event.

The problem I see here is that you are creating new baseCircle, outerCircle, and innerCircle each time. Rather, you should be creating one of each instance and updating it when updateDisplayList() runs.

I'd probably make your instances of innerCircle, outerCircle, and baseCircle variables on the current component. In createChildren() you can add them as children on the component. In updateDisplayList you can do the relevant drawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文