TwelvestoneFlash

would any of you AS3 gurus be willing to share some code?


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Big Ern
 
2008-11-25

for instance something (relatively simple) that uses a number of different bespoke AS3 classes (possibly) including a custom event class?

I am trying to figure AS3 out, but I am not used to event based code.

Something simple like a flash calculator just so I can see how the classes SHOULD work together?

DontBogartMe
 
2008-11-26

yeah this can get confusing when you're starting out and trying to work out how to organise your classes..... perhaps you've got a better grip on this concept now after the other thread though?

Maybe think of it like this... one class creates instances of another class, those instances are considered children of the first class. So we have a Daddy class who creates instances of a Kiddy class. The Daddy knows who his Kiddys are - but the Kiddys don't know about Daddy. When a Kiddy is hungry, he screams out to the world, hoping someone will listen. The Daddy has created listeners to listen out for when one of his Kiddys cries.

So the Daddy class uses addEventListener to listen for events that the Kiddy classes might broadcast. The Kiddy class uses dispatchEvent to dispatch the event.

If a Kiddy has say, a pet Hamster class, then the Kiddy could use addEventListener to listen for events from his pet Hamster. But note that the Daddy can't listen directly to that Hamster's events because he won't have direct access to the Kiddy's Hamster. But the Kiddy class could both listen for a Hamster event, and also use dispatchEvent to broadcast the Hamster event back up so the Daddy can also hear it. When your apps get more complex you may find yourself having to pass events back up the chain like that.

Note that you don't always need to use custom event classes like you have done in the other thread - if you don't need to pass extra data with the event then you can just use a normal Event.

Hope that's of some help, I guess I could whip up some example code if you need it?

Big Ern
 
2008-11-26

Ok, I know I'm dumb, but did you really have to lower it to "Daddy" and "Kiddy" classes? k

Actually, that does help somewhat. One of my biggest issues now (and back with AS2) is:

Do you create an omniscient "Controller" class that says "I want five buttons here" and an FLV Loader there and I want another movie clip over here"?

and if yes:

How do you decide what goes into that class and what goes into the specific button/mc classes? For instance: if you have have a textfield inside a movieclip that you want to populate, do you do it in the mc class or the "Controller" class?

In the example in my other thread, I use a for loop to grab the movie clips out of the library and place them on the stage. Would I populate the textfield inside the loop, or in the constructor of the mc's class?

I have gleaned some info from your entries in my other thread, from JLM's super post in the AS3 book thread and off forums and youtube, but it's often hard to know what the RIGHT way is without getting a comp sci degree.

I have made a concerted effort to get the hacks out of my code. I know you guys are good coders so I thought just seeing how you do it on an actual functioning project would help me look at my code and change it accordingly.

But if you haven't got one handy (or can't share it due to copyright etc) please don't write one specifically for me! You and JLM have put enough bloody time and effort dragging my sorry ass into AS3! k

DontBogartMe
 
2008-11-26

no need to worry about the time taken for these things - I find helping in this way helps me organise my understanding of things too, and also if I lay out my ideas for you, possibly someone else will come along and point out flaws in my code I didn't know existed. Anyway like I said, with this events issue you just caught me as I was picking my way thru it too k

Originally posted by: ernieweaselfat .....One of my biggest issues now (and back with AS2) is:

Do you create an omniscient "Controller" class that says "I want five buttons here" and an FLV Loader there and I want another movie clip over here"?

and if yes:

How do you decide what goes into that class and what goes into the specific button/mc classes? For instance: if you have have a textfield inside a movieclip that you want to populate, do you do it in the mc class or the "Controller" class?

yes I usually create one main class that is sort of the project class - so I don't put code into the FLA, I just make the FLA use my main class (see the "Document class" box in the properties panel).

The textfield should be handled inside the class that shows the movieclip - this is because the parent class shouldn't need to know what that child class does with the text. It could just stick it in a textfield, or alternatively it could create some complex animation by breaking up the text string into characters and making clips out of each letter. The point is, what it does with the text is its business - it should handle it. It's like delegating work and responsibility down the chain of command. Does the boss need to tell his secretary how to use the fax machine every time he gets her to send a fax? Also consider that if you make your child movieclip class know how to display the text, then it's easier to take that class and use it elsewhere. Perhaps you'll never reuse that particular class, but it's a good habit to get into.

I really should be more disciplined in my code and plan my classes before I start coding them, but really I just plow in - I start in the main class and just work down as I need to.

Don't worry too much about 'the right way' for now, just get stuck in, work through the problems you find and you'll learn. And if you keep half an eye on techie forums or blogs or whatever - or even read that damn book occasionally k - you'll pick up the right way and be in a better position to understand it and apply it to your work.

Originally posted by: ernieweaselfat Ok, I know I'm dumb, but did you really have to lower it to "Daddy" and "Kiddy" classes? k

my current family situation is influencing my thinking I reckon k

JLM
 
2008-11-26

Drags ernieweaselfat out of thread into haxe.

Good code can be reused and make sense in 6 months time and strikes a balance between abstraction and getting stuff done asap while being subsectioned/decoupled to allow debugging of problems, there is no right and wrong if it works well and can be maintained easily. i too would love to see others real projects, but I may pm you my hacks later.

Big Ern
 
2008-11-26

DBM -- That makes perfect sense. I'm glad to hear I am at least (sorta) on the right track as I put the textfield populator in the mc class. So basically when you are building a "kiddy" class, you only put stuff in there that applies to the class itself.

So say you want to change a textfield outside the movieclip once, say, an animation is complete. You would simply do that dispatchEvent malarky INSIDE the "Kiddy" class when the animation is done to send a message to a waiting listener in the "Daddy" class? :lightbulb:

JLM -- The PM would be mucho appreciated, mang, if you have the time.

DontBogartMe
 
2008-11-26

Originally posted by: ernieweaselfat So say you want to change a textfield outside the movieclip once, say, an animation is complete. You would simply do that dispatchEvent malarky INSIDE the "Kiddy" class when the animation is done to send a message to a waiting listener in the "Daddy" class? :lightbulb:

Bingo!

Big Ern
 
2008-11-26

Originally posted by: DontBogartMe [quote]Originally posted by: ernieweaselfat So say you want to change a textfield outside the movieclip once, say, an animation is complete. You would simply do that dispatchEvent malarky INSIDE the "Kiddy" class when the animation is done to send a message to a waiting listener in the "Daddy" class? :lightbulb:

Bingo!

[/quote]

SWEET. One concept down, 8 million to go! k

Thanks dude! I kinda feel like I'm getting it... (until the next hurdle). It probably seems quite obvious to most people reading this, but it really helped me.

Storm
 
2008-11-26

not obvious at all ewf, don't feel alone. AS3 is a complete FLIP for those who grew with Flash (without a computer science background as you said). It's a complete new way of thinking and forces you to abandon a lot of your thought processes in building a Flash application.

If I have to hammer something out, I still go AS2 and some of my AS3 projects are hacks approaching it from an AS2 thought process. As an example, I still reference the parents and root in the classes as MCs so I can pass shyte back and forth. I've been reading this thread with interest so you're not alone.

One thing I'd like to get into my head is MVC as the more I use it and talk to those who use it, it's not really MVC, it's start thinking in MVC and then make everything work however you can. And OOP in OOP-based Flash agencies are less OOP than what you're learning now, so I look forward to these threads. These code geniuses here are way more helpful than some of the books out there.

JLM
 
2008-11-27

its interesting large agencies seem to create complex MVC and code libraries that tie your arms and take forever to understand, and do not relate to web short term turn over. smaller agencies never seem to create shared lib so you can spend life creating from scratch!! Small agencies also believe svn is a new word! I am interested in MVC approaches as I am yet to believe that they fit perfectly with flash.

pyrogen
 
2008-11-27

as3 makes executing design patterns easier k

baron ruhstoff
 
2008-11-27

Originally posted by: pyrogen as3 makes executing design patterns easier k

:forest:

Event listeners are your friends. Use them.

Storm
 
2008-12-01

rant

How come when I work on things directly from the Help file in Flash CS3 I get compile errors consistently? How fucking bad is the Help file?

Everytime I try to learn something from Flash itself I get more lost because I get a compile error. Thank God for FlashDevelop I have to say.

Is it just me with Flash's help file?

JLM
 
2008-12-01

Storm

For me the jury is still out on strict typing, wish the adobe engineers had studied ruby rather than java. I am not convinced that they could not have speeded up as1 without strict typing and while I am used to all these external files I sware they are to conform to java dev mind set. 3D is cool and really needs as3 but if I really want to create simple stuff fast as1 is much better than as3. AS2 seems like a broken language somewhere between.

;j

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

would any of you AS3 gurus be willing to share some code?