Hi,

   Here is my 2c

EntryClass.main is a static function, but you cannot guarantee that mxml is going to compile your chart to a static variable - you can't access non-static variables from a static function if I remember rightly...

What you probably want to do here, which would be a lot cleaner is to create a new component in mxml or ActionScript that extends the VBox component. This would have an applicationComplete event handler that did the drawing, very quickly:

Here is the MXML file for your component - right click in the project folder and create a new MXML Component if you are in FlexBuilder, make sure it extends VBox and give it a name - MyChart or something, then edit the source:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox creationComplete="redrawBG()"
   xmlns:views="views.*"
   xmlns:mx="http://www.adobe.com/2006/mxml"; width="400" height="300">
   <mx:Script>
       <![CDATA[
//add the creationComplete handler above and make it point to this function:
           private function redrawBG():void {
this.graphics.drawRect(100,100,100,100);
           }
]]>
   </mx:Script>
</mx:VBox>


If you put the component in the top level folder - same as your App file, then you don't have to create another namespace. If you put it in a folder, then you have to make a "namespace" for that to include it in your App. The code above is stored in a folder called views, so you add the extra attribute to the opening tag xmlns:views="views.*"

Then in your App, do the same to put your namespace in scope:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
        xmlns:views="views.*"
applicationComplete="EntryClass.main()">
   <mx:Panel>
     <views:MyChart id="myChart" width="900" height="300" />
   </mx:Panel>
</mx:Application>

Then that should be a bit neater - I would check out the video tutorials around 
for doing this stuff in Flex, there are some really good ones that got me 
started.

HTH

Glen



steve linabery wrote:
Hello Flashcoders,

Let's say I have two files, myApp.mxml:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
applicationComplete="EntryClass.main()">
    <mx:Panel>
      <mx:VBox id="myChart" width="900" height="300" />
    </mx:Panel>
</mx:Application>

and EntryClass.as:
package {
  public class EntryClass {
    public static function main():void {
      myChart.graphics.drawRect(100,100,100,100);
    }
  }
}


Why does "mxmlc myApp.mxml" complain with this error message:

    quote:
    /path/to/EntryClass.as(4): col: 7 Error: Access of undefined
property myChart.

    myChart.graphics.drawRect(100,100,100,100);
    ^

According to devguide_flex3.pdf:
"The IDs for all tags in an MXML component, no matter how deeply
nested they are, generate public variables of the component being
defined. As a result, all id properties must be unique within a
document. This also means that if you specified an ID for a component
instance, you can access that component from anywhere in the
application: from functions, external class files, imported
ActionScript files, or inline scripts."

I thought perhaps this would work:
package {
  public class EntryClass {
    public static function main():void {
      var mxmlApp:Application = Application(Application.application);
      mxmlApp.myChart.graphics.drawRect(100,100,100,100);
    }
  }
}

but mxmlc complains about this with:
/path/to/EntryClass.as(7): col: 15 Error: Access of possibly undefined
property myChart through a reference with static type
mx.core:Application.

Any suggestions appreciated!

Thanks,
Steve
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



--

Glen Pike
01326 218440
www.glenpike.co.uk <http://www.glenpike.co.uk>

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to