A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: AS, XML and memory

  1. #1
    Junior Member
    Join Date
    Jul 2001
    Posts
    14

    AS, XML and memory

    Hi,

    I have a webgame that I built, that I want to recreate in flash. It's a turn based game you can check out here: www.terrapollicitus.com

    I have the basic idea of what I think I need to do in my head, but need a few questions answered.

    1. The actual game processes I plan on processing on the server because they require database calls. I'm planning on setting up a webservice that I will make calls to, and pass back xml to the flash game. My question is, does the flash game keep these in memory? Meaning, do I need to clear them out somehow?
    2. Another memory question here, if I pass values to the flash game that it will continue to use unless updated from the database, will they stay in the memory?
    3. Can AS handle multi-level arrays?

    If this is in the wrong section, please move it and let me know where these types of questions should go. Thanks in advance.

  2. #2
    Hood Rich FlashLackey's Avatar
    Join Date
    Aug 2006
    Posts
    148
    1. If you're using web services, it probably wont be necessary to deal with XML since all of the approaches Im aware of send in data structures native to flash (XML is not with AS2 but will be in AS3). The flash player manages the memory for you. You dont need to do any clearing as in many other languages. Some loaded content (images, sounds, etc) will be cached but data from remote calls will not be.

    2. Any values passed into flash will be gone once the swf is closed unless you specifically store them on the hard-drive. The current method to do this is to use the 'SharedObject' which is well documented on adobe.com. It has some limitations but can be used to store a small amount of information for between sessions.

    3. Yes. AS can use multi-dimensional arrays and objects.

    Interesting project btw. Ive been working on something somewhat related for some time now (a multi-player, turn based strategy). send me a private message if you're interested to know more about it/discuss.
    "We don't estimate speeches." - CBO Director Doug Elmendorf

  3. #3
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    to clarify : flash does do its own garbage collecting, and an admirable job of it really - but only after all references to the object are removed - which 99% of the actionscript i've seen - on this board or anywhere else - doesn't do. this isn't a bug or a failing of the player - this is 'appropriate' behavior - but very misunderstood. the key is scope: keep everything local to a function call, and it'll expire the instant the function's done executing. use "var" every time you can, recycle your timeline variables, and make good use of the arguments array as it's passed local as a native behavior.

  4. #4
    Junior Member
    Join Date
    Jul 2001
    Posts
    14
    Quote Originally Posted by moagrius
    to clarify : flash does do its own garbage collecting, and an admirable job of it really - but only after all references to the object are removed - which 99% of the actionscript i've seen - on this board or anywhere else - doesn't do. this isn't a bug or a failing of the player - this is 'appropriate' behavior - but very misunderstood. the key is scope: keep everything local to a function call, and it'll expire the instant the function's done executing. use "var" every time you can, recycle your timeline variables, and make good use of the arguments array as it's passed local as a native behavior.
    So if I want the flash file to keep the variable I keep it outside of a function, and if I don't want it to hold the value place it within a function?

  5. #5
    ___________________
    Join Date
    May 2004
    Posts
    3,174
    if you meet two conditions :
    1. you use the "var" keyword
    2. this happens inside a function statement

    your variables will be locally scoped. no others are. local variables are massively faster than those that arent.

    properly scoped local vars:
    code:
    function bob(a,b,c){
    var d = 100;
    trace(a/d+b*d-c%d);};


    executing bob will leave a nice clean swiff when it's done.

    improperly scoped vars stick around. check the debugger.
    code:
    function bob(a,b,c){
    d = 100;
    trace(a/d+b*d-c%d);};


    note that the only difference is the ommission of "var". similiarly, "var" doesnt do anything when not implemented within a function statement.[as]
    code:

    a = 1;
    b = 2;
    c = 3;
    var d = 100;
    trace(a/d+b*d-c%d);

    there's no difference between d and the others in that example, because it didnt happen in a function call.

    this behavior is known as "function-block" behavior. other languages have different rules, but all the ecma's act the same way - as i described just above.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center