Flex Multiple mxml to one Action Script - apache-flex

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?

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.

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.

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.

Related

Where to put common Functions/Constants in ASP.Net MVC

I am new to ASP.Net MVC. I have a couple of controllers and models. They all use a set of static functions and constants which I call common code.
In my MVC project I have folders for Controller, models and view etc,
Where is all the common code supposed to be put ?
Is is OK to create a Common folder and create new class for my static functions and same for global constants ?
If you reuse this common code often across solutions, you might want to consider compiling it into its own class library and simply referencing the assembly.
Another thing you'll want to consider is the nature of the common functions. Are they truly just helper functions (like manipulating strings and stuff like that) or do they make more sense mixed into your business layers?
Basic rule is to keep it organized be consistent. There's no right or wrong way to structure your application...only hundreds of thousands of opinions.
Exactly you can create Helper folder when you set your extension methods or another common utility.
But for constants suggest you to create Ressource File
Remarks : All text , warning or info messages, put theses elements in ressource and don't write in code, for gloabalization need(It's my case on project)

Unstructured Actionscript file and ActionScript Class?

I am new in ActionScript . I want to know that when should we use an Unstructured ActionScript file and when should we make a Class of ActionScript file? Does it effect the performance of Application ?If yes , HOW??? Please help me finding the comprehensive answer of above question.
Thanks!
Regards
I can only think of a handful of instances in which it might make sense to use a non-class based structure in an ActionScript project:
You're quickly prototyping a simple piece of functionality (even then it's just as easy, assuming you're using ActionScript 3.0, to put your code in a class and set it as the Document as it is to use a non-class file via include)
You're dealing with non-class based legacy code
You're using the timeline to structure your code (usually not a great idea for anything much more complicated than a banner)
You're writing your project in ActionScript 1.0 (in which case you should really consider upgrading)
In all other cases, the tiny hit in performance resulting from the additional scaffolding of a class-based system will be more than offset by the advantages of it being well-structured.
If you're using Flex, I think you'll have to work quite hard not to use classes.

Share getter/setter classes across asp.net applications

Maybe there's something obvious that I'm missing or maybe not. Suppose I have a class that is just a representation with getters/setters and no logic. I'm going to use these structures for serialization/deserialization mostly. Suppose I use that object in many, many applications. Suppose I have dozens of these objects. What's my best approach to sharing these objects?
I understand that I can compile an object into a DLL and reference that DLL. But if I have dozens of these objects, do I compile them all separately so I can use just what I need or do I make and maintain a monster DLL with all of these objects in it. Both of those approaches seem bad. I don't want to create a class library for every single class (that's stupid) and throwing them into a giant package just seems like a bad idea.
Am I missing something simple? Doesn't java have a convention where one can create jar files of one to many classes? Does .Net do something like that?
You need a happy middle ground.
You should be grouping related objects into individual namespaces.
You can then compile each namespace into a seperate DLL. That way, whoever is using the libraries only needs to reference a single DLL per group of functionality.
You can have a master assembly containing all objects. Then also create separate assemblies for the different applications where you only add the ones you use as links.
You would then use Project->Add Existing Item, and then on the Add-button click the down-arrow and select "Add As Link" when you add the classes you want.

ColdFusion CFC implementation of C# Partial Class?

Does ColdFusion offer a mechanism for splitting CFCs into multiple files? I am NOT talking about extension, I am talking about splitting the SAME CFC into multiple files; the same way C# allows for "partial" classes. The reason for this is because I am using T4 to generate a bunch of CFCs and I want to be able to tag functionality onto the generated CFC by doing so in another file. I want to do this in a way that doesn't violate the Open-Closed Principle.
<cfinclude> will work as far as basic functionality is concerned, however the following will not work correctly:
Metadata functions - only the functions within the inspect CFC will be shown - not the cfincluded functions
<cfajaxproxy cfc="your.cfc"> will not allow the included methods to be called through javascript
Calling included functions as a web service call will not be possible
(all these cases basically boild down to the metadata only seeing the functions etc. which are within the base cfc)
It might be worth you googling Coldfusion Mixins for more detail on this and other related techniques.
No, sorry. A limitation of the language, I'm afraid. A CFC is a single file.
I mean, of course, you could bastardize it somehow. You could have fragments that are wrapped in a cfcomponent tag as part of some kind of build process, but I'm pretty sure that's not what you're looking for here.

How can I best convert an AS1/AS2 application to an ActionScript3 application?

I have a program consisting of multiple SWF's. An AS2-SWF loads a bunch of AS1-SWFs.
It's a crappy program. I'd like to specify the GUI in MXML and perhaps refactor some code to AS3. However, converting all of the 300+ symbols to AS3 or whatever is undoable.
What are my options in converting to AS3/Flex/MXML? The app is very simple, only also quite large. It consists only of buttons, backgrounds and attention-texts. All the button texts are in XML files.
I want to turn this into pretty code ASAP but also controlled so the code becomes:
easily updateable/maintainable,
readable
learnable (so I can have the updating done by someone that can only script AS3 or even MXML).
Of course doing this is on my own initiative, if it'll take more than a week, I won't be able to find the time.
Regards, Jurgen
This might help:
http://flexman.info/2009/03/29/as3converter-an-ant-task-small-collection-of-as3/
It's mainly for AS2 code, so FLA editing is out of the question. But you should certainly look into JSFL.
There are some pretty good scripts out there already dealing with something like this:
http://bumpslide.com/blog/2009/03/07/jsfl-class-generator/
What this command does is that it
looks through your library and finds
all library items that have a custom
linkage class name. If the class
extends flash.display.MovieClip (or if
the base class is blank), it checks to
see if a classfile exists, and if not,
it creates it for you. When it does
this, the script looks at all the
items on the timeline and adds
relevant properties to your class. If
these clips are instances of other
components, they will be typed as
such, and relevant import statements
will automatically be added to your
class. If your component is set to
extend some other class (for instance,
com.bumpslide.ui.Button), no class
will be generated. Class files will be
written to the correct package
location inside the first custom class
path defined in your publish settings.
Jurgen, I feel for you... it sounds like a lot of work.
What sorts of issues do you have? are all the swfs treatable as different classes? is there much overlap in the logic or does each object have a specific role?
I think having so many different SWFs may possibly lead to scoping problems> which swf talks to which. you may be able to set up something with as3 that uses the existing parts and then try making a facade over the existing code > use the existing logic in the swfs and do the visual part through mxml. other than that, all I can advise is a rebuild. you might find yourself in need of a swf decompiler too if you are missing some of the original fla's

Resources