Attaching / Importing AS3's and MXML in Flex 4?
Typically, in a PHP setup, you can simply use
include('includes/myphpfile.php');
to incorporate seperated parts of PHP code and / or HTML markup. Now when it comes to Flex 4, I'm not quite sure how I'd go about doing that same thing, only this time, for ActionScript files. I want to do this kind of approach since my source code gets really annoyingly huge as t开发者_开发技巧he Flex app I'm developing grows. That's why I want to separate it into small chunks to avoid getting myself overwhelmed with too much code to see at a time.
I strongly recommend you learn about building Flex Components. That is the preferred method of encapsulating code and breaking up a single 'file' into multiple components and you'll thank yourself in the long term for learning those skills.
The answer your posted can help you move ActionScript to a different file:
<fx:Script source="MyActionScript.as">
But it is not the same as building reusable encapsulated codee. You can also use the include directive to accomplish the same thing:
<fx:Script><[[
include "MyActionScript.as";
]]></fx:Script>
The include directive can be used in ActionScript components / classes too, while the Script source attribute is MXML only.
That said, relying on the include file is often considered a crutch and is not a decision I would take lightly.
Hey I found out how to do it while Googling around. For those interested, here's what I did:
<fx:Script source="myactionscript.as" />
Hope that helps others as well!
精彩评论