Need help with class system in AS3 !!!

A place for tutorials on how to get the most out of Flash

Need help with class system in AS3 !!!

Postby OwnerOfSuccuby » Sat Jul 13, 2013 7:28 am

Can some body post it or link on it ? Why some people say it is too comfortable is it really true ? I did not see any good example where it is really better - can some body explain it with some simple example - why is it so good and how to work with it ?
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Need help with class system in AS3 !!!

Postby IrrelevantComment » Sat Jul 13, 2013 11:39 am

1) Look at how code in AS2 works. You can place code anywhere, on object, in objects, on timeline, in classes. What this means is that you have a complete clusterfuck of code spread out over hundreds of places. If your program isn't working, or if you want to change a piece of code and can't remember where it is, or if you are looking at a .fla that somebody else made, this is a nightmare. AS3 + classes puts all the code into one place. Want to change how Krystal acts? Look in Krystal.as. Want to change how the menu behaves? Look in Menu.as.

2) Classes can be used to create pure AS3 games without Flash Pro being used at all, using only free software.

3) Using classes allows you to use an external IDE (such as FlashDevelop - http://www.flashdevelop.org). This is great, as the built in IDE is absolutely shit.

4) Classes allow you to access features that can't be used otherwise, such as static vars, static functions, constants etc

5) Classes allow you to write code once, and not multiple times.

I have a class called Key.as that I use in every project. It records all key presses and allows me to check if a key is down with just if(Key.isDown(69)). That means that in my games, there is not a single keyboard event listener. How would you achieve that without classes?
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Need help with class system in AS3 !!!

Postby OwnerOfSuccuby » Tue Jul 16, 2013 2:39 pm

I am not good in it. I understand how some of that stuff works - but i really need to understand how it is creating in adobe flash for example.

How to create it from Zero (I do not know anything about it unfortunatly) - and how to use ? For example i have some class that have to write A / another B / another C (trace it)

How to create it frome adobe flash cs6 and make it understand that it is its project class ? How to use it then ? All I see was projects with one class and I did not understand how and why do they make it :lol:

So for example class buttons - how to make object move on button press if i have class buttons for example ? Him and only him not all objects ?

The link you give me is unfortunatly to hard for me. I understand the class idea - how all this private functions work in perfect world (read some books and etc) - but have zero exp in flash with it :( They always say if we have - but fuck - if I need to create it not have it what to do - where it wrigh - where call it. :mrgreen:

I hate books :? :twisted: :roll:
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Need help with class system in AS3 !!!

Postby IrrelevantComment » Wed Jul 17, 2013 12:42 am

So for example class buttons - how to make object move on button press if i have class buttons for example ? Him and only him not all objects ?


A class describes a concept of an object, say for example a car. The class says what properties a car has: make, model, speed etc and what a car can do and how it does them: accelerate, brake but the class itself doesn't have a particular speed, and you can't call a function on it. What is the speed of a car? How does the concept of a car accelerate? You can't answer these questions. What you can do is have an instance of a car, and you can ask, what is the speed of this car? What happens when this car accelerates?

let's say you have a class such as this:
Code: Select All Code
public class Car{
  public var speed : int;

  public function accelerate(){
    speed += 5;
  }
}


Then if you say:
var car1 : Car = new Car();
var car2 : Car = new Car();
you are creating two separate instances of the car class.

so if you write car1.accelerate() you are just making the first car accelerate, and not the second one, and not the class itself. Does this answer your question at all or have I missed the point?
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Need help with class system in AS3 !!!

Postby OwnerOfSuccuby » Wed Jul 17, 2013 8:23 am

Yes I understand it better now, thank you, but how to create it - or just put as file in the same directory as main progect ? How to connect classes to my project ?
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Need help with class system in AS3 !!!

Postby KaTsuO_O » Thu Jul 18, 2013 3:01 am

This post is not supposed to be offensive, it is only the point of view from someone that have used Actionscript 2.0 and is perfectly happy with it. As it provides everything I personally need in order to create the things I want to create.

Part 1: http://www.youtube.com/watch?v=VIQrEGm8kB8
Part 2: http://www.youtube.com/watch?v=eMRngAk3TS4

I'm sorry, but I really don't get classes either. Why spend all that work setting things up? I could just start typing in the actions panel and get the same result, without that extra work.

And my reply to point 1 to 5 would be:

1) Being able to place codes in any place you like is a good thing, as it provides options for the creator. If you want you can place code in a button, the same code will work in any button without any changes to the code. You can also write a button code on the timeline using instance names, it is all up to preference. If it all is a mess in the end, then it is the creators fault, not the programming language itself. If you want to look at someone else's file, just ask the person how it is set up. Want to change how Krystal acts? Click on the Krystal symbol and open the actions panel. Want to change how the menu behaves? Click on the frame that the menu is on and look at the actions. If you don't want it to be a clusterfuck, then don't make it a clusterfuck.

2) That is fine and dandy, but as soon as you have Flash, this "feature" becomes pointless.

3) I honestly have no idea of what that is, all I know is that I have not needed it so far, after almost 10 years of using the program.

4) Same goes or this one.

5) Quite simple, Make a function.

Again. This post is not supposed to be offensive, it is only the point of view from someone that have used Actionscript 2.0 and is perfectly happy with it. As it provides everything I personally need in order to create the things I want to create.
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Need help with class system in AS3 !!!

Postby OwnerOfSuccuby » Thu Jul 18, 2013 5:25 am

Thank you very much Katsu. In this example class is not nesessary ;) as in a lot of them.
But now I have a little time and idea may be they really can help some how - so i decided to try to find situation where it is hard or impossible to make with out class files.

So if i find it i will post it ;)

Yes i already can understand some +/- of this. For example for big project - if you need to fix code and have a bad internet - you can send some body the only fix of as file.
But it is the stupidest situation becouse - it takes more time to fix bug then send the file in our time.

To use other people classes with out retranslation them is good too - but if they do not use classes you will not need to retranslate it :oops: :mrgreen:

So i decided to try to program some thing on it :roll:
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Need help with class system in AS3 !!!

Postby IrrelevantComment » Thu Jul 18, 2013 9:13 am

AS3, and classes in general, force you to adhere to stricter guidelines for better code writing. And yes, that may mean that coding some things is a bit harder, and maybe the initial coding is longer. But in the long run it does save time. It took me about 15 minutes to write that Key.as file that handles all my keyboard input, which is longer than I would spend on KeyListeners in one project. But honestly, how much time do you think you have spent, over your ten years, writing keylisteners? And how much time debugging them when they didn't run correctly because you mistyped and in AS2 Flash doesn't give errors for that?

to 3) I would say that is about as relevant as me saying I've never used Illustrator, therefore the ability to import illustrator files isn't useful. I think anyone who has done any programming in various languages will agree that the Flash IDE (Integrated Development Environment - that's the bit that allows you to write code) is shockingly bad. Off the top of my head it lacks: auto-formatting, decent syntax highlighting, code completion, hotkeys, function generation etc. It is without a doubt the worst IDE I have used in the last 5 or so years.

to 4) if all instances of a movieclip share some data, how would you handle that?

to 5) make a function where? On the timeline for an object?
IrrelevantComment
 
Joined: Tue Mar 15, 2011 7:46 pm

Re: Need help with class system in AS3 !!!

Postby OwnerOfSuccuby » Thu Jul 18, 2013 11:37 am

Okey good example from video do not work on my PC let us go way number 2:

So i can not have more then one package or as file on PC & Only one ? And all have to be there ?

What to do if i want for example 5 as files for one project - where i want to write different functions ?

Why is it better then include for example ?
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Need help with class system in AS3 !!!

Postby KaTsuO_O » Thu Jul 18, 2013 3:10 pm

If you're talking about, if (Key.isDown(Key.Space)) { and similar. I have used them quite a bit, but I only had that problem in the beginning. Once I had used them a few times, It wasn't a problem anymore as it was second nature to type "Key", instead of "key". It would be great if it could show an error, but when you type "key" then it doesn't turn blue as the rest, which in it self is an indication.

3) In that case, the ability to import Illustrator files wouldn't be useful to you, but could of course be useful to others. At the moment, using different IDE, does not seem useful to me as I'm perfectly happy with Flash's IDE. Again, it could be useful for others. Auto format is in there, I'm not sure what kind of code completion you're talking about, but there is code completion as well. For example, if you write, "if (Key.", then a menu will pop up showing the different options. You can then add "is" and isDown will be highlighted which you can just press enter to add it. After you add "{" and press enter to make a new line, it will automatically add "}". I can't speak for the rest however.

4) I don't really understand the question, could you give me an example of a situation?

5) Yeah, put the function on the first frame where you load all the variables and such, then you can call it back later. I consider that a way to only write something once, of course, you have to write the name of the function multiple times if you want to call it for different situations, but there is no way around that.
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Need help with class system in AS3 !!!

Postby GoRepeat » Tue Jul 23, 2013 12:45 pm

I have been converting some stuff to AS3 and thereby slowly learning it (need as3 for Air to properly export .FLA to .apk/iOS), and classes threw me for a loop at first, but really they do end up being a better concept than they way it is handled in AS2.

Think of a class as an archtype of an object. In AS2, you might have an enemy movie clip (let's say). This movie clip will be in your library and have a bunch of code embedded in it so the game knows how that enemy will act when you drop it on the stage using attachMovie or whatever mechanic you use to spawn and generate enemies. The benefit of this is that the enemy is a nice and neat little self contained package. The drawback of this is that if you have 20 copies of the enemy on the stage, AS2 becomes really, really code intensive trying to manage, organize, and maintain the integrity of those 20 enemies.

In AS3, the concept of a "class" solves this issue. Instead of having "enemy" as a library object that is self contained, you would have "enemy" as a class in which all that previous functionality is contained. Now, when you drop 20 enemies on the stage (var enemy1 = new enemy(), addChild(enemy1)), you can control their variables directly using the class mechanics without all the messy extra monitoring code that you had in AS2. That is the best way to think about it - classes help you maintain that comfortable structure while still physically handling all the code in one place.

I used have the same opinion as you KaTsu - that I felt "more" organized in the AS2 environment where all the code was written to individual objects and snippets. After playing around in the new environment, though, the merits of AS3 are starting to really come out. Depth management is another huge improvement in AS3 as everything has a specific index value that represents its layer instead of the seemingly randomness and explosiveness of AS2 depth handling.

One of the most accurate things I read was that AS2 is more oriented for designers because you tend to organize and think based on the objects and designs you create. AS3 is more oriented for coders because you tend to organize and think based on the events and actions being performed. I still think AS2 is a lot easier, but the jump to AS3 wasn't as bad as I thought it would be. And like I said, AS3 is required for mobile gaming development ;D
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Need help with class system in AS3 !!!

Postby FruitSmoothie » Sun Nov 03, 2013 11:32 pm

Gorepete Wrote:I have been converting some stuff to AS3 and thereby slowly learning it (need as3 for Air to properly export .FLA to .apk/iOS), and classes threw me for a loop at first, but really they do end up being a better concept than they way it is handled in AS2.

Think of a class as an archtype of an object. In AS2, you might have an enemy movie clip (let's say). This movie clip will be in your library and have a bunch of code embedded in it so the game knows how that enemy will act when you drop it on the stage using attachMovie or whatever mechanic you use to spawn and generate enemies. The benefit of this is that the enemy is a nice and neat little self contained package. The drawback of this is that if you have 20 copies of the enemy on the stage, AS2 becomes really, really code intensive trying to manage, organize, and maintain the integrity of those 20 enemies.



Good example. I was just watching some tutorials about classes in AS3 and couldn't figure out exactly why they were needed/better since I've never used AS2. It also explains why I've heard that AS3 is much more efficient (why I started trying to learn it first).
FruitSmoothie
 
Joined: Mon Jun 27, 2011 8:54 pm

Re: Need help with class system in AS3 !!!

Postby Terrantor!!! » Tue Nov 05, 2013 6:35 am

Hey guys, I'm new to as3, as well. I think a really cool feature of classes is inheritance and polymorphism. This grants child classes the abilities and properties of its parents. Take for example the movieclip class, a sprite with a timeline. Through importing the movieclip class and extending it's attributes, u can build custom movie clips, stop, play and any other custom things u add to it. U can even override established functions of said parents. This is the easy part. Instead of creating a whole new movie clip, u just extend the pre made code and modify what u need. All the above is possible with ur homemade classes and highly encouraged for simplicity and efficiency.

That said, I do miss the ease of actionscript 2's listener functions and the ability to traverse roots, parents, and thises. Really hard to accomplish in as3. I just had more control.
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Need help with class system in AS3 !!!

Postby GoRepeat » Tue Nov 05, 2013 2:17 pm

Terrantor!!! Wrote:That said, I do miss the ease of actionscript 2's listener functions and the ability to traverse roots, parents, and thises. Really hard to accomplish in as3. I just had more control.



This used to drive me nuts too, but then I found out you can just use MovieClip(this.root).whatever or MovieClip(this.parent).whatever the same way you would have used _root.whatever or _parent.whatever in AS2
Picarto LiveStream: https://picarto.tv/GoRepeat
Other Stuff: Click Here
User avatar
GoRepeat
Moderator
 
Joined: Wed Jul 21, 2010 2:26 am
Location: Behind the Looking Glass

Re: Need help with class system in AS3 !!!

Postby FruitSmoothie » Tue Nov 05, 2013 10:45 pm

Man I wish some of you guys would do tutorials or stream yourself coding and explaining some things or something. It's pretty overwhelming to start off (Especially since I'm trying to learn animation and improve my art at the same time). I just try to learn one or two new things a day, I figure eventually I'll understand enough. Shaymus22 on youtube is a pretty good teacher, I don't think he has many videos though. People usually stop past the basics in video tutorials (For good reason, as I'm sure it'd be very difficult to explain some of the advanced stuff).

I'm not sure how to go about making code for a game as efficient as possible really. I feel like if I try to piece things together, it's going to turn into a mess. I'm kind of worried about learning bad habits. Is it just best to start by getting things to work and worrying about efficiency later? Time to mess with some very basic games...
FruitSmoothie
 
Joined: Mon Jun 27, 2011 8:54 pm

Re: Need help with class system in AS3 !!!

Postby Terrantor!!! » Wed Nov 06, 2013 5:52 am

Gorepete Wrote:
Terrantor!!! Wrote:That said, I do miss the ease of actionscript 2's listener functions and the ability to traverse roots, parents, and thises. Really hard to accomplish in as3. I just had more control.



This used to drive me nuts too, but then I found out you can just use MovieClip(this.root).whatever or MovieClip(this.parent).whatever the same way you would have used _root.whatever or _parent.whatever in AS2


Thanks for the protip, man!! I'll be sure to try it next time I dip in the code. I'm taking a small break right now. One thing that is bugging me is how you can generate a movie clip onto the stage during instantiation. Any help from anyone is appreciated.

FruitSmoothie Wrote:Man I wish some of you guys would do tutorials or stream yourself coding and explaining some things or something. It's pretty overwhelming to start off (Especially since I'm trying to learn animation and improve my art at the same time). I just try to learn one or two new things a day, I figure eventually I'll understand enough. Shaymus22 on youtube is a pretty good teacher, I don't think he has many videos though. People usually stop past the basics in video tutorials (For good reason, as I'm sure it'd be very difficult to explain some of the advanced stuff).

I'm not sure how to go about making code for a game as efficient as possible really. I feel like if I try to piece things together, it's going to turn into a mess. I'm kind of worried about learning bad habits. Is it just best to start by getting things to work and worrying about efficiency later? Time to mess with some very basic games...


I am for this. I'd b that guy; I lack the internet connection, though. I could build an as2 boot camp thread, alternatively.
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Need help with class system in AS3 !!!

Postby FruitSmoothie » Thu Nov 07, 2013 4:04 am

Maybe there'd be some more games being worked on if this site had some more in depth tutorials for actionscript and such. I've seen people do things so differently, it's difficult to know which method is best to use. Like I started watching a series and noticed the comments were saying they were teaching bad habits and I'm all "Crap", lol.
FruitSmoothie
 
Joined: Mon Jun 27, 2011 8:54 pm

Re: Need help with class system in AS3 !!!

Postby OwnerOfSuccuby » Thu Nov 07, 2013 2:21 pm

I finally understand how to make classes in flash :lol: How it all works - but for now much more comfortable to me is "not to use them".
Becouse i really do not understand why it is much better then my method.

Yes i see a lot of new good stuff when i see about classes - but they work with out them too. So may be i am just not on that level where i will need classes :lol:

I am low level character in the world of flash :lol: - so i have to level up more to understand classes. May be it is true. May be i just do not need them for now.

But now i know how use both methods and it is good. :roll:
OwnerOfSuccuby
 
Joined: Fri Jun 11, 2010 9:33 pm

Re: Need help with class system in AS3 !!!

Postby Terrantor!!! » Sat Nov 23, 2013 3:55 pm

Don't give up, man. Classes are 75% of as3. Once u understand them, everything else just starts falling into place. I was in ur position not two months ago. I just stuck with it and now I consider myself an as3 extraordinaire. U won't regret it, either. I love as3. It really forces u to make one really good piece of reusable code and cuts back on ur debugging time.
User avatar
Terrantor!!!
 
Joined: Thu Aug 23, 2012 10:36 am

Re: Need help with class system in AS3 !!!

Postby hat973 » Tue Dec 09, 2014 7:21 pm

I understand the code its like deeper down the road that pisses me off still my brother gave me this site that has a mother load of links http://www.flashdevelop.org/community/v ... =13&t=7186 it has links out the wazoo
Red light panda

:ugeek: Tumbler: Tumbler
:geek: I have a Blog: Red Light Blog
;) I stream to Give me a Watch over at: Picarto
:mrgreen: Donate: Patreon
:roll: Discord:Discord
User avatar
hat973
 
Joined: Tue Apr 24, 2012 12:44 am


Return to Tutorials



Who is online

Users browsing this forum: No registered users