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.
Related
I'm working in a tool that is supposed to generate some Java Code to accelerate part of the development based in a swing input dialog...there is no need to get any further with it so I'm going to my problem...
I need to retrieve all the attributes from a class to check whenever it is necessary to add a new one. I tried to use reflection but things started getting complicated. In order to use reflection I need to compile the class I want to get the attributes as it does not work directly from .java file, .class is required for it.
The problem is that many of the classes has a lot of dependencies! Due to some design flaws some classes are a high coupled, so if I am supposed to dynamic use a class loader to compile a class A I would have to retrieve and compile all its dependencies! And then retrieve all the possible dependencies from the class A dependency classes!
I made a test running an existing ant file to compile to whole project instead of the above approach but it takes about 9 minutes to finish! From the final user perspective waiting 9 minutes every run is not accetable!
Does any one here knows a better solution???
If you want to avoid working with reflection and bytecode, it means that you will have to parse the .java files yourself with a grammar and, well, a parser based on this grammar. It is possible (especially if you do not implement the whole grammar, because many java features might be useless in your project perimeter), but I reckon this is no easy task.
There is an Apache commons Sandbox package called ClassScan. It is capable of doing the kind of source parsing you appear to require. http://commons.apache.org/sandbox/commons-classscan/. Note that it is in the Sandbox, so not part of the Commons Proper.
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.
I'd like to be able to generate a class that inherits from BitmapData at runtime. Is this possible in Actionscript 3? If so, what is the syntax?
I do not think that you will find yet a mature library to do that. There are two open source projects for dealing with ABC bytecode manipulation but they seems to be in infancy. You can take a look on at http://code.google.com/p/flemit/ and http://code.google.com/p/floxy/
As the author of flemit / floxy (though both were only created for asmock), I would recommend looking into AS3Commons Bytecode as it is under active development (flemit/floxy are not).
AS3Commons Bytecode is actually based on the Loom project and has been extended to use a much cleaner API than flemit was ever intended to have.
I've never seen that, but you could probably mimic that sort of behavior with a static class that you can feed standard BitmapData objects into at runtime...
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
HI,
I'm currently working on a project that uses Flex and Java. In Java we easily enforced a coding standard with Checkstyle, and we want to do this for Flex.
Does anybody know of a tool similar to Checkstyle that would allow coding standard checks?
(I've googled for this but found only one project written in python and it seams abandoned)
Thanks
The long and the short is that there is... kind of, but only for Actionscript, and you have to test it yourself... There is a prototype of an Actionscript 3 version, but it is not even in Beta yet (and I admit that I haven't had the time to test it). I haven't found anything similar for XML, let alone MXML. This is in at least one list of feature requests for Flex 4, however.
I'm working too on a project uses Flex and Java. Like you, in Java, we easily use plugins like checkstyle, findBug, javaNcss or PMD. My personal project is to do this for Flex. I have test the prototype 'checkStyleas3' but it just verify the code source en returns you 0 or -1 as result. So you will have (me too in fact), to implement this prototype if you want to do more than that.
Keep an eye on this : http://blog.joa-ebert.com/2009/05/20/as3v-preview/