I figured it out. It has to do with how Repeater initializes it's
inner components. I guess Flex doesn't know the actual type of the
innercomponent until "repeatEnd" gets fired.

Please see the code below. Here init() is the callback for my
component's "creationComplete" event:

private function init():void
{
    rp.addEventListener(FlexEvent.REPEAT_END,
function(event:FlexEvent):void
{
    img.addEventListener(Event.COMPLETE, onImgComplete);
});
}

This way no complaint from compiler.

--- In flexcoders@yahoogroups.com, "gwangdesign" <[EMAIL PROTECTED]> wrote:
>
> Hi guys,
> 
> Thanks for the replies.
> 
> The code below actually works. In my AS version, I did import all the
> classes including mx.events.FlexEvent, etc.
> 
> For events, I use "complete" on Image as opposed to other events is
> that I am interested in when the SWFLoader (parent class of Image)
> completes loading the content, not when the Image component is
> instantiated by it's Repeater wrapper (in which case you would listen
> to "repeaterEnd" which is fired BEFORE any events from the Images get
> fired).
> 
> I guess my problem would be to find a right place in the component
> life-cycle to register the complete event, but I am not coding a
> custom component just MXML...
> 
>  
> --- In flexcoders@yahoogroups.com, "Amy" <amyblankenship@> wrote:
> >
> > --- In flexcoders@yahoogroups.com, "gwangdesign" <gwangdesign@> 
> > wrote:
> > >
> > > I am loading 50-ish something images using an Image control wrapped 
> > in
> > > a repeater wrapped in a VBox component. I want to do some stuff 
> > once I
> > > know the full dimensions of the VBox, which is when all the images
> > > have been loaded.
> > > 
> > > Here is the code snippet:
> > > 
> > > <mx:VBox id="imgBx">
> > >     <mx:Repeater id="rp" dataProvider="{dp}">
> > >         <mx:Image id="img" width="120" height="80"
> > > source="{dp_arr[rp.currentIndex]}" complete="onImgComplete
> > (event);"/>
> > >     </mx:Repeater>
> > > </mx:VBox>
> > > 
> > > /**AS3*/
> > > private function onImgComplete(event:Event):void
> > > {
> > >     if(imgCounter<imgTotal-1)
> > >     {
> > >         imgCounter++;
> > >     }else
> > >     {
> > >   configure();
> > >     }
> > > }
> > > 
> > > Everything seems work fine at this point. The problem comes when I 
> > try
> > > to immigrate the onImgComplete() from inline MXML into ActionScript,
> > > basically as an event handler for this component like so:
> > > 
> > > creationComplete="img.addEventListener(Event.COMPLETE, 
> > onImgComplete);"
> > > 
> > > I got the following error:
> > > "TypeError: Error #1006: addEventListener is not a function."
> > 
> > You might need to add curly brackets around it to get it to evaluate 
> > as AS.  You might also want to look at the events associated with the 
> > Repeater control, since they are probably more appropriate.
> >
>


Reply via email to