1 Reply Latest reply on Dec 15, 2009 5:16 AM by Wiouou

    Need example of trival MXML Canvas (separate file) then added to display list in WindowedApplication

    remoteportal Level 1

      Um, sorry about this, but I'm a newby and I've been trying to get this to work for several days now and can't figure it out; I can't get it to compile:

       

      The prefix "mx" for element "mx:Canvas" is not bound.

       

      I can't figure out Flex namespaces!

       

      --> Can someone please quickly create a simple MXML Component based on Canvas that says "Hello, Canvas", then add that to the display list in a AIR (WindowedApplication) main file? <--

       

      It would be nice to have actually TWO examples: adding to WindowedApplication via ActionScript (addChild) and via MXML (<mx:MyCanvas...>, etc.).

       

      I have five Flex books now and they don't really seem to cover how to "call" a custom component.  All the examples create components inside the WindowedApplication (and NOT in a separate MXML file).

       

      Pete

        • 1. Re: Need example of trival MXML Canvas (separate file) then added to display list in WindowedApplication
          Wiouou

          mxml:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:core="mypackage.*">
               <core:MyCanvas width="100" height="100"/>
               <mx:Canvas width="100" height="100"/>
          </mx:WindowedApplication>

           

          script:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
              <mx:Script>
                  <![CDATA[

                             import mypackage.MyCanvas;

                             import mx.containers.Canvas;

           

                             private function init () : void {

                                   this.addChild (new MyCanvas ());

                                   this.addChild (new Canvas ());

                            }

                  ]]>
              </mx:Script>
          </mx:WindowedApplication>

           

          the file mypackage/MyCanvas.mxml contains:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
             
          </mx:Canvas>