5 Replies Latest reply on Jul 1, 2010 9:54 AM by Flex harUI

    how to cast getElementAt() returned element

    Malena Mesarina



      The BorderContainer getElementAt() method returns an IVisualElement component that I want to cast as a Menu, since I pushed a Menu component into the BorderContainer in a previous line, but I get the following compiler error:


      >>Implicit coercion of a value with static type mx.core:IVisualElement to a possibly unrelated type mx.controls


      even after I used the "as" syntax to specify that I want to cast the returned IVIsualElement to a type Menu.


      Does anyone know how to do this?

      Or how to use the getElementAt() method properly, since this seems to be a very common operation.





      The code:


      public function Initialize():void {
                       var myMenu:Menu = Menu.createMenu(null, menuData, true);
                       //myMenu.show(10, 10);
                       var m:Menu =  metrics_bc.getElementAt(0) as Menu;