3 Replies Latest reply on Jan 19, 2012 7:41 AM by Claudiu Ursica

    addChild or addElement? from swc to flex stage?

    _willCrain Level 1

      I usually just write applications as Actionscript projects. Now I trying to work with some of the newer flex components so I am working in a Flex Project.

       

      No issues with the components really but I would like to know how to add a MovieClip from an assets.swc that I created in the Flash IDE to the stage of the flex app. This way I can use the flex components with my own custom MCs.

       

      As a side question, how do i init a function as soon as the view loads. I tried adding an eventListener for the ADDED_TO_STAGE but that threw an error too.

       

      I have a feeling that I am just missing the relationship of the stage and how to place on and call things to it.

       

      Thanks in advance.

       

      I was trying something simple like this:

       

       

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

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                               xmlns:s="library://ns.adobe.com/flex/spark"

                               actionBarVisible="true" fontSize="17" tabBarVisible="true" title="title">

           

             <fx:Script>

                               <![CDATA[

                                              private var alert:Alert;

       

                                              protected function btnTester_clickHandler(event:MouseEvent):void

                                              {

                                                             alert = new Alert();

                                                             alert.title.text = "TEST COMPLETE";

                                                             addChild(alert);

                                              }

                               ]]>

             </fx:Script>

                     <s:Button id="btnTester" x="250" y="0" label="Button" click="btnTester_clickHandler(event)"/>

      </s:View>

       

      Results in:

      Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.

                at spark.components.supportClasses::SkinnableComponent/addChild()[E:\dev\4.y\frameworks\proj ects\spark\src\spark\components\supportClasses\SkinnableComponent.as:1123]