Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 migration, display list strategy questions..

LEGEND ,
Aug 31, 2010 Aug 31, 2010

Hello all, this is a bit of a strategy question for larger scale flash apps. I've been holding back on AS3 for obviously a very long time and I have some basic questions.

I'm very used to building things with hard references in mind using AS2. I build it knowing I'm going to put a panel A in _level0.panela_mc and interface B in _level0.interfaceb_mc and Login Prompt in _level0.login_mc.login_com, etc etc.. I always know these will exist and you simply reference them via _level0.whatever. What is the new strategy to managing references to lots of sprites?

If I build a panel in a class method, the var somepanel:Sprite = new Sprite() I create inside the method to hold the panel I'm making will be up for garbage collection if I don't make sure a reference stays intact (via either add it to a display list, add an event handler, etc..). The reference "somepanel" I made in the method will go out of scope at the end of the method as well. Should I expect to have needed to make a class variable ahead of time to store a reference to this? Should I be keeping a class genericObject:Object that holds a list of references to everything I ever make almost like a global registry?

I'm just used to AS2. You just create a movieclip and when the method ends, the clip still exists and you know the _level0.ref.ref.ref will always exist and how to get back to it.

How are larger projects managed where content loaded isn't known ahead of time and the layout is rather dynamic. What are the strategies used to manage all that dynamic chaos?

Lastly I'm so overly used to being able to target a movieclip using a single daisy chained list of clips, like: _level0.this_mc.that_mc.those_mc. I noticed I can't seem to do this approach with the getChild() approach. using someSprite.getChildByName('this').getChildByName('that').getChildByName('those') doesn't work. How do you drill down into nested clips? I did notice I can do it one level at a time, such as: refA = someSprite.getChildByName('this'); refB = refA.getChildByName('that'); refC = refB.getChildByName('those'); .. Is that what I'm expected to do?

Thanks for some tips!

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Aug 31, 2010 Aug 31, 2010

>>Should I expect to have needed to make a class variable ahead of time to store a reference to this?

Yes, instead of making a local variable inside a method, make a class variable - then the reference will not be GC'd until you set the variable to null.

So you say:

private  var somepanel:Sprite;

And then in some method:

somePanel = new Sprite();

>>I'm just used to AS2. You just create a movieclip and when the method  ends, the clip still exists and you know the _level0.ref.ref.ref will  always exist and how to get back to it.

AS3 can work much the same. Like you said, doing an addChild on some MovieClip or sprite will negate you from having to keep a reference. Example:

function testClip():void{

  var a:Sprite = new Sprite();

  a.graphics.beginFill(0xFF0000);

  a.graphics.drawRect(0,0,50,50);

  addChild(a);

}

Because the sprite is now on the display list, it won't be garbage collected, even though a was a local variable. There are no levels (thank god) in AS3 but the sprite/clip exists in whatever container you placed it in - running that function on the main timeline and just saying addChild places the sprite on the stage.

>>Lastly I'm so overly used to being able to target a movieclip using a  single daisy chained list of clips, like:  _level0.this_mc.that_mc.those_mc. I noticed I can't seem to do this  approach with the getChild() approach.

Well, you don't really use that approach when you're doing object creation directly with code. You don't need instance names - you just use the reference you got when you created the object. If you need you can keep an array of references. On the other hand if you're building content clips in the IDE for use by your code, then you can reference instance names like you always did. For example say you want to build a simple alert box - so you make a new movie clip. Then you place a dynamic text field inside of, and give it an instance name of theText. In the library you set the dialog clip to export for actionScript and give it a class name of myDialog. In your code then you could do:

var dialog:myDialog = new myDialog();

addChild(dialog);

dialog.theText.text = "Hello World";

Here you can directly reference the myText text field inside the dialog.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2010 Aug 31, 2010

Thanks for the responses! Very helpful.

So for large complex applications people are keeping references at class level to the parts they need quick access to?

Thanks for the tip on the IDE. I try to do nothing more than set the SWFs main class and that's about it though as I ran into uncountable issues when merging things like fonts with AS2 using some dynamic text fields and some embedded text fields. What a nightmare!

That being said, are the font issues of AS2 resolved with AS3? My least favorite issues of AS2 is the random glyphs it decides to embed regardless of what you tell it to embed. Also importing a font into the library only includes specific OS codepage glyphs in random fonts and in others it works fine. Sometimes fonts won't work in a library clip but will only work in a dynamically created TextField without embedding the font, etc etc etc. Are any or all of these issues addressed in AS3?

edit, another reply while I was replying:

Andrei~ I agree it's inefficient but sometimes projects get bloated in unexpected ways. Larger apps expected to be simple one-time use apps end up going multiple generations and then you find the whole thing really needs to be redesigned to be efficient but the clients budget can't support it. It happens to me quite a bit actually when something is more successful than it should be and grows unexpectedly.Sadly I don't always have the time necessary to give every project perfect code when everything is a fire drill.

In AS3 I can see the display list is neutering my ability to do things quick and dirty with lots of hard references. I love a clean project so I'm happy that the display list will keep me honest.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2010 Aug 31, 2010

Larger apps expected to be simple one-time use apps end up going multiple generations and then you find the whole thing really needs to be redesigned to be efficient but the clients budget can't support it.

I know what you mean. But in the context of transition from AS2 to AS3 there is no way code from AS2 will work in AS3 - this is a total redesign anyway and as such it takes time.

It happens to me quite a bit actually when something is more successful than it should be and grows unexpectedly.Sadly I don't always have the time necessary to give every project perfect code when everything is a fire drill.

Code is never perfect. BUT, I feel that of the main skills of developer is to architect an application in such a way that it is scalable. In other words, keeping in mind that requirements contantly change and thinking one step ahead is what makes code efficient. In a way, "bloated" is the result of overlooking possible changes/forks in use cases and not utilizing language capacities.

In AS3 I can see the display list is neutering my ability to do things quick and dirty with lots of hard references.

It may sound strange, but I think once paradigm shift occurs, actually "quick and dirty" is much faster on AS3. I strongly believe that getting away from timeline coding is a key to sucessfull AS3 application. I believe it is all in the head.

Just one example. For an AS2 Flash designer it feels safe and natural to place an object on timeline and manipulate it from the code in a frame. AS3 makes it extremely easy to place/remove object from the library to any display list in the application. Even from practical aspect writing the lines:

var myMC:MyLibraryObject - new MyLibraryObject();

addChild(myMC);
myMC.x = 20;

myMC.y = 20;

is much faster than going through manual labor of grabbing it from the library, placing it on stage, moving another layer, positioning it via Flash IDE UI, etc.

That being said, are the font issues of AS2 resolved with AS3?


Dealing with fonts in AS3 is quite an extensive topic. Although, again, it feels natural to embed fonts at authoring, it really makes big convenient difference not to use TextFields on stage for purpose of making fonts available to entire application. As a matter of fact it is better to load fonts at runtime. But it may be too advanced in the beginning.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2010 Aug 31, 2010

When I meant recode, I meant in the same language

Sometimes you create a project and it's really quick and dirty, proceedural faking as a class, etc.. Then it grows legs and you need to get it done in 15 minutes rather than the 2 hours you'd need to wrap it in a proper class/pattern structure and you just bite the bullet and keep going proceedural.. Maybe it just happens to be but I doubt it. My business moves quick

On fonts, all I really want is fonts to be treated like any other runtime loaded asset. I hope they are in AS3. I don't care that a font may be 15MB, I just want to load all or a partial subset of it EXTERNALLY and make that available to all TextFields in the application. In AS2 I have no way to load a TTF or OTF externally so I'm excited to see how that works in AS3. With everyone having a nice DSL/cable/fiber connection today it's not a huge issue to download a 5MB font if it really advances the design.

That said I also hope AS3 makes better use of OS fonts. Can you simply request to use a OS font and have it antialiased in AS3?

Lastly what design pattern would best lend itself to a large flash application? Is MVC good enough?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2010 Aug 31, 2010

With everyone having a nice DSL/cable/fiber connection today it's not a huge issue to download a 5MB font if it really advances the design.

Well, it is still a problem. I am sure I am not the only one and I never wait for 5MB Flash blobs to load unless I am forced to. I just move alone and never come back to such a site. There is no reason with current technology for a web based application NOT to be respectful to my time.

Again, loading fonts at runtime is a way to go IMHO. Unless they are Asian fonts, they are usually not more than 40-50 KB including entire subset.

Can you simply request to use a OS font and have it antialiased in AS3?

Unless something big happened recently - the answer is no.

Lastly what design pattern would best lend itself to a large flash application? Is MVC good enough?

In general design pattern should serve application needs not vice versa. I think it is a big mistake for new developer to start with design patterns. In many cases established design patterns are a huge overkill from both performance and compactness. As a matter of fact, any application architecture ends up with some pattern even if developer has never heard of patterns.

As for MVC, because it is not really a design pattern but an OOP concpet, it is nice to know about.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2010 Aug 31, 2010
LATEST

On embedding 5MB+, of course I'm talking about huge asian character sets in the multi tens of thousands of glyphs.. I regularly localize projects in Sim/Trad Chinese, Korean and Japanese.Most of the elegant asian fonts are 10MB+. I end up using MS UI Gothic on anything I know people won't wait to download.. Every other latin-esque font I've used is under 80k and is typically 30k.

I'm sorry to hear unembedded fonts aren't antialiased :/. do they still disappear when rotated, etc?

And I completely agree the proper pattern must be used but flash and actionscript are so specialized that very few patterns fit the strange mix of a scripting language with a multimedia engine built in. I've found MVC to be useful but overall no more pattern usage than registries or singletons or other simple patterns. And MVC is a pattern, not a concept. Although yes, not a design(er) pattern as much as a It's an architectural. It's the only pattern I've found that fits some of the systems I've built which is why I asked what other people seem to mix well with flash.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 31, 2010 Aug 31, 2010

I addition to quite comprehensive post of dmennenoh's,I would like to point out that the following approach:

_level0.login_mc.login_com

is a very inefficient in both AS3 and AS2 at best. Chasing children from several levels up (as well as parents) is extremely tedious and offers little flexibility. Application architecture (not display list content) that requires this kind of drill down should be revised.

Display list model in AS3 is well structures. It doesn't have holes and has no negative depth indexes. Finding objects on display list is as easy as looping through an array.

AS3 offers huge array of ways to reference objects anywhere in the application. This includes wide usage of events.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines