0
votes

In my Application, I have four mxml files and one ActionScript file. I want to know how I can access that one action script from 4 mxml files without Specifying <mx:Script source="one.as" any Idea?

3
So, you've got a fully supported ridiculously easy way to do this... and you don't want it? That said, you could turn that AS code into some form of class, and use an instance of that class in each MXML file. (Preferably using a singleton pattern)Sam DeHaan
I don't think there is any other way, and why is this method not helping you?midhunhk
Yeah i knew.. but In my project i have 60-70 mxml files. if i want to pass a msg like an Alert... I jus want to change in a single method. not to dig ma head to long..to avoid tat i have asked this..this Pretty complicated and it tends to us to be different..tats it!ConquistadorAravinth

3 Answers

1
votes

Lots of ideas. One way you specify in your post.

Another way:

<mx:Script>
 include "one.as"
</mx:Script>

A third way is to encapsulate that as file functionality into a class and then create an instance of that class in each MXML file.

0
votes

Just remember the simple fact: file is a set of bits to store your data. The data stored in *.mxml and *.as files is programming code in OOP manner (in case of you're doing things right). So it has no sense to talk about files in this case. Lets talk about classes which are represented by MXML and AS files.

The directive <mx:Script source="one.as" is about files. I never use it because it is a kind of hack. Even Adobe itself uses includes only in case of embedding version number and some class metadata. I recommend you to forget about this hack at the beginning of learning Flex. You can use it wisely in the future (maybe or maybe not: I never use it only using old good OOP design principles and haven't any problems).

So now we realized about OOP and classes. So use MXML and AS classes using OO principles. This book can help you to learn OOP and design patterns.

0
votes

As I said in my comment on the original question, and as @www.Flextras said in his last point, wrapping the AS functionality into a class is a great idea.

I would recommend one step further, as I did in my original comment, and create that class as an implementation of a singleton pattern. In this way, you're using a single instance of the class throughout an application, which will ensure the object is identical between MXML components.

Alternatively, if it works properly (hard to tell with no detail) you could also implement the functionality in static methods of some form of utility class, this would also be a good implementation.