PDA

View Full Version : two AS3 newbie questions


Incrue
04-01-2006, 09:58 AM
1 If i dont want to use classes,can i make the same way as before, putting all the code in the first frame?And it still works with the new player?

2 Now i have to import the properties i want to use too?I mean, isnt enough to import flash.display.movieClip, also if i want to use _alpha have to import flash.idunknowant.alpha ?

hangalot
04-01-2006, 01:20 PM
not sure about not using classes. flash 9 has not been released yet so I don't know how thats going to go, but i suspect it will work like that.

no you only have to import the class, properties and methods are availible on the class, nothing else required.

Incrue
04-02-2006, 02:11 PM
So, when they say:
'_alpha is deprecated, now use:flash.display.DisplayObject.alpha'
doesnt mean i have to
import flash.display.DisplayObject.alpha;
rigth??

hangalot
04-02-2006, 02:12 PM
it means you have to use .alpha on your movieclip/displayobject/sprite

Incrue
04-03-2006, 08:00 PM
What i want to know is if, in the beginning should i
import flash.display.MovieClip;
import flash.display.DisplayObject.alpha;

or just
import flash.display.DisplayObject.MovieClip;

mrand01
04-03-2006, 08:19 PM
just movieclip. Movieclip is a class, it has to be imported, alpha is a property that is specific to an instance of that class, it does not have to be imported. only import classes

abeall
04-05-2006, 06:31 PM
Can I just do
import flash.*
That would be so much nicer.

hangalot
04-05-2006, 06:32 PM
yes you can, but then it will only import the classes in the flash package.

webninja
04-05-2006, 06:40 PM
If you're not sure what to import, omit the import statement and let the compiler do the work. It will tell you what you're missing, then just go add it in.

hangalot
04-05-2006, 06:41 PM
or press ctrl-o or enter behind the class.

Incrue
04-06-2006, 03:28 PM
So, now one more question...
what is binding?
Here
http://labs.macromedia.com/wiki/index.php/ActionScript_3:Learning_Tips
they say:
"Binding should always be done to strongly-typed data items, not to properties of type Object.
The lack of type safety with type Object can result in accidental coding mistakes, so the compiler will flag this as a warning. Binding to a property of something of type Object, such as selectedItem.name, will cause a warning; you need to use strongly-typed data items and cast, as in EmployeeInfo(selectedItem).name."

hangalot
04-06-2006, 03:31 PM
a binding is a way to make your view or model update automatically. the flex framework allows you to write certain metaTags and the compiler then generates the code for you to take care of what happens in terms of the stuff getting updated.

Incrue
04-07-2006, 11:45 AM
I dont know if i should create a new thread cos those are not just two questions anymore
1 public and private are now public and internal, rigth?

2 What is override?

3 What is Dereferencing?

hangalot
04-07-2006, 12:50 PM
there is public , protected, private and internal.
public is easy to understand.
protected works like this: if i have an instance of the class a protected method acts like a private method aka i can't call it from the outside. however if i subclass that class, i can change the bahevaiour of the function by overriding it, but then i have to use the override keyword to signify that i am overriding existing behaviour. and i can call that protected from subclasses
private works the same in terms of its visibility from the outside, but i cannot override the methods in subclasses nor call it.
internal's scope means its availivble to all classes in the same package and suclasses.


i think you should get what the override keyword does from what i have said already.
dereferencing means deleting a variable that holds a reference to an object. its not like an oficial term, but search garbage collector and refrence counting.

webninja
04-07-2006, 10:43 PM
Keep in mind that binding is done at compile time. That means something like this won't work:

var x:uint;

x = {boundProperty} * 3;

No error or warning will be generated, but you'll get the value of {boundProperty} without it being multiplyed by 3.

Incrue
04-08-2006, 02:47 PM
there is public , protected, private and internal.
public is easy to understand.
protected works like this: if i have an instance of the class a protected method acts like a private method aka i can't call it from the outside. however if i subclass that class, i can change the bahevaiour of the function by overriding it, but then i have to use the override keyword to signify that i am overriding existing behaviour. and i can call that protected from subclasses
private works the same in terms of its visibility from the outside, but i cannot override the methods in subclasses nor call it.
internal's scope means its availivble to all classes in the same package and suclasses.

Inst best OOP practice to use get and set?Like function getSomething and set like setSomething?And when making a class defining wich methods and properties others should have acess?So i dont understand this stuff to acess things who weren't designed to be acessible
So, its sounds like a useless things to learn, cos if i will have acess to internal stuff only with get and set i can just make only those methods public and all the rest of the other things private, or internal,or protected

webninja
04-08-2006, 05:56 PM
In any OO design, it is very good practice to isolate access to the internals of a class so that only members of that class or classes derrived from it have access.

Getters and setters are basic practce and in AS3 there is even a dedicated syntax for it which aids binding.

One of the goals of OO design is to promote code resuability. This is accomplished by coding classes that do a specific bit of work. You start out with a classes that accomplish very generic tasks and then subclass the class a few times adding specificity. you'll find that you can then reuse the base classes. If you go accessing the varibals from all over your code you won't be able to reuse it. Have a look at the AS3 class lib docs and you'll see just how often they use the same classes near the root of the tree.

When you have a bug, you'll have a lot of trouble figuring out what can change what. As your conventional non-OO project grows, fixing bugs will become more complex. When every varible is global and you have functions that access stuff from all over your source, it does not take long before you lose track of what's happening. Any little change can impact the whole project, which leads to more bugs.

Incrue
04-09-2006, 09:48 AM
Ok
What i didnt understand is:When making the class you design what everyone everywhere will have acess, and these will work with get and set, right till here...
So when comes to internal, all other classes in the package can acess the thing, but arent they acessing things who are not suposed to be acessible?
So that this is not best oop practice?
Now override, i supose override is:i take some method, change what he does but keep his name
I may be wrong, but i understand that i should use -protected- only if i intend to make some subclass override some method of my class
But again, isnt this against the good oop practice?Cos someone is acessing thing who were not designed to be acessible?
And when i am going to need to do this?

Tink
04-09-2006, 11:48 AM
No this is better OOP than what you can do with public and private alone.

Lets say you have a method that ONLY other classes in the same package can access. You can now limit the access to what is required using internal. This is much better than making it public to everything.

This works the same with protected. If you subclass a class and you need to access it methods in your subclasses you can mark the method protected. This limits the access to subclasses only. Without it, you again would have to make it public. Therefore you can now be stricter, which is better.
i should use -protected- only if i intend to make some subclass override some method of my class
That is incorrect. You use protected for any method or variable that you want to access from a subclass.

override is used when you want to alter a method that is inherited from you superclass. It must return tha same type and take exactly the same parameters as the original method.

You may also be interested in 'final'. specifying a method as final means that it cannot be overriden. so if you had a superclass with a method you want to be able to access from a subclass, but you don't want your subclass to be able to override it, you specify the original method as final.

// This cannot be overriden, but can be accessed by subclasses.
protected final function methodName():void
{
// Actions here.
}

Incrue
04-09-2006, 12:11 PM
Ok, thanks everyone for the help

hangalot
04-09-2006, 09:17 PM
rule of thumb: make things as private as they can be.

webninja
04-10-2006, 07:11 AM
Keep in mind that the best practices for OOP are by no means set in stone or widely agreed upon. In C++, you don't have something like package access but you do have multiple inheritance, which is either a gift from God or Satin, depending upon your perspective.

Classes bound together in packages are expected to have knowledge of each other and be trusted and therefore OO designers give more access to them. If you're writing a class library for others to use in their development, you don't ant them having access to your class internals. I'm not a fan of package access myself.

On override, remember that the goal is to change the behavior of your class without changing it's type. The text book example is to have a shape class that has a draw() method. From Shape you derring square, circle and so on. You then create a bunch of these, att ehm to a container, and invoke the draw method on each. You don;t care which is a circle or a square, you just call draw() ont ehm all and whatever they are gets drawn. Of course, each subclass (circle, square) overrode the draw() method from the base class Shape.

abeall
04-13-2006, 03:16 AM
or press ctrl-o or enter behind the class.
Hm? Ctrl-o as in File > Open? And "enter behind the class" I'm not sure what you mean... I'm on Flash 8, not Flex.

So, is Flash 9 going to have a idiot/designer mode that automatically imports needed classes when compiling? That would be nice.

hangalot
04-13-2006, 03:18 AM
in eclipse ctrl-o is organise imports, so all the classes you have used and not imported (and the claases you imported but did not use) are all sorted out for you.

don't code in the IDE imo, checkout sepy or fdt

abeall
04-13-2006, 03:46 AM
in eclipse ctrl-o is organise imports, so all the classes you have used and not imported (and the claases you imported but did not use) are all sorted out for you.
Ah, got ya. When you say eclipse, do you mean Flex? Am I correct that Flex is an eclipse based application? (My ignorance is overflowing on this subject!) Sounds very handy... I'd still love to see Flash/Flex [optionally] automatically import all classes if needed at compile time. I don't see why not?

don't code in the IDE imo, checkout sepy or fdt
I'm not a developer.

hangalot
04-13-2006, 03:38 PM
you write code. yes flex 2 uses eclipse as its base to write and compile code in

webninja
04-14-2006, 05:24 AM
Eclipse is an open source development environment that's very popular, especially with Java developers. The Flex environment is a plugin for Eclipse.

I read on another forum that Adobe might give away the compiler, debugger, class libs and such, but charge for the Eclipse plugin. This is wild speculation, but if it turns out that way it would be amazingly ironic.

hangalot
04-14-2006, 06:21 AM
i suspect everything expect the ide plugin and the debugger will be availible for free. however dataservices (aka fds) will be on a non entreprise level from what i have read. there are already other tools to code as3 and flex2 mxml in (primalscript i know for a fact - but i know about other projects as well) so life is good.

personally i will pay the <$1000 for the flex2 plugin just so i can have the brilliant java like debugging.

Tink
04-14-2006, 05:22 PM
I read on another forum that Adobe might give away the compiler, debugger, class libs and such, but charge for the Eclipse plugin.http://weblogs.macromedia.com/cantrell/archives/2006/01/flex_beta_2_and.cfm