Consider the following code
<fx:Script source="Script.as" />
......................
<s:Group>
<s:layout>
<s:HorizontalLayout/>
</s:layout>
<s:Spacer width="10" />
<s:Button label="1" click="doSomething()"/>
<s:Button label="2" click="holder.getCanvas().testDraw()"/>
<s:Button label="3" click="doSomething()"/>
</s:Group>
<s:Scroller id="canvasGroup" width="650" height="500">
<s:Group>
<local:CanvasHolder id="canvas" />
</s:Group>
</s:Scroller>
I want to move buttons in a separate module (let’s call it Toolbar.mxml). Thus I’ll need to move <fx:Script source="Script.as" /> (in Script.as I use canvas as well). Here’s my questions:
- How can I see
canvasvar inToolbar.mxml(and can I)? - Is it possible somehow to pu
<fx:Script source="Script.as" />so that it could be seen fromToolbar.mxml.
You won’t be able to automatically “see”
canvasinToolbar.mxml. I would recommend using Flex’s Event architecture to access it.Alternatively, you can pass the canvas object to the Toolbar directly.
Yes, the second option is much simpler, but the first option is often useful when the components that need to talk aren’t easy to pass to each other.
You can put
<fx:Script source="Script.as" />inToolbar.mxml, if that’s what you need. If you need to call functions in the scope of the parent, I would recommend using the Event architecture again, as opposed to some kind ofparent...orApplication.application...call.