0
votes

I have an actionscript file that defines a class that I would like to use inside a Flex application.

I have defined some custom controls in a actionscript file and then import them via the application tag:


<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:scorecard="com.apterasoftware.scorecard.controls.*"
...
</mx:Application>

but this code is not a flex component, rather it is a library for performing math routines, how do I import this class?

2

2 Answers

5
votes

You'd need to import the class inside a script tag.

<mx:Application
  xmlns:mx="http://www.adobe.com/2006/mxml">
  <mx:Script>
    import com.apterasoftware.scorecard.controls.*;
    // Other imports go here

    // Functions and other code go here
  </mx:Script>

  <!-- Components and other MXML stuff go here -->
  <mx:VBox>
    <!-- Just a sample -->
  </mx:VBox>
</mx:Application>

Then you'll be able to reference that class anywhere else in your script tag. Depending on how the class is written you may not be able to use binding within the MXML, but you could define your own code to handle that.

Namespace declarations are only used to import other MXML components. AS classes are imported using the import statement either within a Script block or another AS file.

0
votes

@Herms: To clarify a little, namespace declarations can be used to "import" AS classes as well, when you're going to instantiate them using MXML.

For example, consider having a custom visual component you've written entirely in AS, let's say com.apterasoftware.scorecard.controls.MathVisualizer. To use it within MXML:

<mx:Application
    xmlns:mx="http://www.adobe.com/2006/mxml"
    xmlns:aptera="com.apterasoftware.scorecard.controls.*">

    <aptera:MathVisualizer width="400" height="300" />
</mx:Application>