开发者

Action script 3 - I need to know if a child object has changed it's size DYNAMICALLY ! help?

I'm writing a sort of "dynamic gallery" in flash. The problem is that a child of the gallery can 开发者_JAVA百科be resized in runtime, and then I have to rearrange the gallery.

Now, of course, I can't overload the gallery items, since it's a display object which is unpredictable. and even if I could force overloading on the items, how will I be notified if, let's say, an animation started, something move, and the item got bigger..

Is there some sort of Event for a display object which is dispatched on ANY kind of resize ??

My dumb solution was to go through all the gallery's items and rearrange them every given milliseconds, and now I feel so dirty and I need to confess my sins.


Well you can tackle this in two ways, either the child object dispatches an event when its size changes or you keep listening to any changes in size with an EnterFrame event, the latter being closer to your "dirty" solution :) personally i usually go for the first solution but this is not to say that the second solution is bad, it's a matter of choice.

  • Is there some sort of Event for a display object which is dispatched on ANY kind of resize ??

You can create your own.

package events
{
import flash.events.Event;

public class SizeEvent extends Event
{
    public static const CHANGE:String = "Size Changed";
    public var params:Object;
    public function SizeEvent(type:String, params:Object)
    {
        super(type);
        this.params = params;
    }

    override public function clone():Event
    {
        return new SizeEvent(type, params );
    }
}
}

So when you add your items to the gallery you write the following:

  galleryItem.addEventListener(SizeEvent.CHANGE , sizeEventListener );

And when an animation ends in the galleryItem

 private function onAnimationComplete():void
 {
    var params:Object = {x: this.x , y:this.y , width:this.width , 
                          height:this.height, //any info you need  etc... };

    dispatchEvent( new SizeEvent( SizeEvent.CHANGE , params ));
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜