4 Replies Latest reply on Dec 17, 2013 7:57 AM by Craberoid

    Reference to child element

    Yue_Hong Level 1

      How can we reference to an element which is added dynamically on runtime?

      Example code:

      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark"

          xmlns:mx="library://ns.adobe.com/flex/mx" applicationComplete="init(event)">




          import mx.events.FlexEvent; 

          protected function init(event:FlexEvent):void {


              var newbtn:Button = new Button();

              newbtn.label = "New Button";

              newbtn.id = "button3";

              newbtn.name = "button3"; 









      <s:HGroup id="mygroup">

          <s:Button id="button1" label="Button 1" />

          <s:Button id="button2" label="Button 2" />




      When I try to run above code, it dispatch error

      Error #1069: Property button3 not found on project1 and there is no default value.

      So, how can I call to the newly added button?


      Thank you.