PDA

View Full Version : Extended UIComponent not dispatching draw event...


timwjohn
10-26-2006, 01:25 PM
Hello everyone! I'm having a bit of a problem with a component class that I'm making which extends UIComponent.

Basically, my new component is dispatching the resize event, but not the draw event, and it's the draw event that I'm after...

Can't see why. I'm just inherriting the UIComponent, and I'm not overriding either the setSize function (which dispatches "resize" in UIObject) or the redraw function (which should dispatch "draw" in UIObject).

Anyone got any ideas?

Cheers!

timwjohn
10-26-2006, 02:10 PM
Hey, I did some checking and it seems that none of the built-in components I've tried dispatch the "draw" event either. I still don't know why, but instead I've made a custom event that I added to the end of my overridden draw() function, and that works.

Though if anyone has any info on why the draw event isn't being dispatched when it should it would be good to know...

Thanks

.Bruno
10-26-2006, 03:02 PM
The following code fragment of the UIObject class definition shows that a draw event is dispatched at the creation of an UIObject, provided that the value of validateNow is true :
function UIObject()
{
constructObject();
}

// sets up the order of construction of a component
function constructObject(Void):Void
{
// this gets called when being defined as the prototype
// don't do anything, just return.
if (_name == undefined)
{
return;
}

// initialize variables and the like;
init();
// create child objects
_createChildren();
// create accessibility if needed
createAccessibilityImplementation();
// hook extension
_endInit();

// draw it now
if (validateNow)
{
redraw(true);
}
else // or draw it later
{
invalidate();
}
}

/**
* redraws object if you couldn't wait for invalidation to do it
*
* @param bAlways if False, doesn't redraw if not invalidated
* @tiptext Redraws an object immediately
* @helpid 3971
*/
function redraw(bAlways:Boolean):Void
{
if (invalidateFlag || bAlways)
{
invalidateFlag = false;
// all textfields are hung off this method so we can call them as well since they don't
// have their own enterFrame event
var i:String;
for (i in tfList)
{
tfList[i].draw();
}
draw();
dispatchEvent({ type:"draw"});
}
}

/**
* mark component so it will get drawn later
* @tiptext Marks an object to be redrawn on the next frame interval
* @helpid 3966
*/
function invalidate(Void):Void
{
invalidateFlag = true;
onEnterFrame = doLaterDispatcher;
}



Because I don't work a lot with timelines, I am never really hundred percent sure what is meant with redrawn on the next frame interval.