Strange Flex callLater x position Behavior
I'm not sure exactly where this is happening, but what I'm trying to do is make a scrolling ticker using flex, and it works fine when there is one of them on the screen, but when there are two, strange things happen.
The way I have designed this for live updating, when the child of my hbox goes off the screen, I remove it and add another child to the end of it. This happens to reset the X position of the hbox, which isn't too bad, but it also resets the X position of any other hbox I have on the screen. Here is code that demonstrates what I'm seeing:
To use this, run the flex program, then click in the first hbox to set its x position to your mouseX. When the x position of the second hbox (hbox3) is reset, so will the first hbox's (hbox2) X position.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="addToBoxes()" xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" >
<mx:Script>
<![CDATA[
import mx.controls.Button;
private const speed:Number = 1;
private function moveBox3():void{
box3.move(box3.x + speed, box3.y)
if(Math.random() > .99 && box3.numChildren > 0)
box3.removeChildAt(0)
callLater(moveBox3)
}
private function addToBoxes():void{
for(var i:int = 0; i < 8; i++){
开发者_开发知识库 var a:Button = new Button;
box2.addChild(a);
a.label = "Box2:" + String(i)
}
for(var j:int = 0; j < 8; j++){
var b:Button = new Button;
box3.addChild(b)
b.label = "Box3: " + String(j)
}
}
]]>
</mx:Script>
<mx:HBox id="box2" width="100%" click="box2.x = mouseX" borderStyle="solid"/>
<mx:HBox id="box3" width="100%" creationComplete="moveBox3()" borderStyle="solid"/>
</mx:Application>
How can I prevent this from happening, or what is a better way to make an updating ticker like I am trying to do?
The problem still exists, but I found away around. For the record, I ended up making a custom component that handles the scrolling internally (canvas instead of HBox also, so you can reference children, and it doesn't jump when you removeChild). I just put two of those on the stage and it works well enough.
精彩评论