A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Accessing data in root folder

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    33

    resolved [RESOLVED] Accessing data in root folder

    I make a little game engine program for a specific game I was working on, with a considerable section of the code in the timeline of a .fla file. I plan on using the same code for both that game and another game, so I was going to move all the timeline code into a separate class, and move that and other classes into one folder which both games can access.

    Each game will then have a separate .fla file holding the graphics and music and preloader and such, and another file holding other data specific to each game (probably .as class with static properties) in a separate folder, and will end up being complied as a .swf file with all the data embedded into it. Currently the extra data is just stored in variables in the classes which need to use them.

    I'm unsure how to set it up so the non-specific game files can access that other file (in the same directory as the .fla file), depending on which .fla file the classes are accessed from.

    So how should I do it?

    The only way I can think of doing it is sending a reference to an object through the arguments of the non-specific classes, which would be pretty messy as only one or two classes need to use it, and to get to those it would have to go through other classes.

    Also if there's a better way of storing data than using static property, let me know. (It has to be embed at compile-time, though.)

    Any help would be appreciated

  2. #2
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    Lets see if I got it straight,

    You want to:

    set it up so the non-specific game files can [be] access[ed] ... depending on which .fla file the classes are accessed from.
    Well, lets see if im on the right track here:

    You wrote some code that you wish to reuse in a different project. However there are some parts that are necessary for one program to use, and other parts which must be used solely in the other program.

    What if you had a class which takes a parameter that is used to 'switch' the function of the class.

    For instance:
    (in pseudo code - I am far too lazy right now)

    PHP Code:
    pack{
        public 
    myClass(token:String="PlanA"){
            switch(
    token){
                 case
    /// blah blah blah- set variables etc here.
            
    }
        }
    }

    //then inside of the FLA or where ever you are creating the instance:
    var my:myClass = new myClass("PlanA");

    //then inside of the other FLA use:
    var my:myClass = new myClass("PlanB"); 
    So when you init your class, you can set a little 'ear mark' for what it is supposta do.

    I would be pretty unhappy with you if I was in charge of updating your code... but it might be the sort of stop gap that you are looking for. Every other line of the class could read 'if(plana){//this}' then the next 'if(planb){//this}'... etc... this is very hard to debug, write and update.



    Honestly, for this type of thing you need to really think out the structure of the class and how best to implement it. OOP is your friend!

    If you really want to make a game framework that can work in a different project--- well firstly dont do anything worth while in the fla; Secondly, make lots of classes that extend functionality. Get a good working 'base' for what you want it to do, and extend that for the specific project. Get each class workable for what they are meant to do, then when you extend that class for a more specific usage, you can overwrite functions and update them to be more useful/accurate.

    For instance, lets say you have a physics game like bowling. Get the physics bit working just right, and apply that to the ball and the pins into a bowling class. Lets say in a different game, you wanted to make 'underwater bowling' (wooooow), just extend your same physics classes and make necessary corrections in a new class specifically for underwater bowling. The bowling game should use the bowling classes, and the underwater game should use the underwater classes (and never the twain shall meet).

    I like this solution better; It is easier to use, easier to fix/update and easier to add new additions into it or use in other projects. How that fits in with your current implementation, I dont know, but if you plan on making any more games with it, it should really help.

    Then lastly, how does one make flash look for AS files that are not in the same directory? Well you just go to Edit, then Preferences, then click on the Actionscript list item, then click 'Actionscript x.0 Settings...'. Then go to Source Path, click the plus symbol and add your path to the files.


    Hope that is helpful,
    _gK >^,^<

  3. #3
    Member
    Join Date
    Nov 2009
    Posts
    33
    Yeah, I understand what you mean with the classes and stuff. I probably didn't quite explain what I meant though (as usual).

    So currently my program is very object-orientated. Only a small amount of code is in the fla, and I'm planning on moving all of that into another class anyways, so that the game can work without me having to copy and paste code into fla files for each variation I make.

    I already have put all the classes that are common to both games in one folder, and then have other necessary classes in the directory of the fla file.

    The main problem is that there is data that I need to send to these classes, values for certain variables that would change between each game (basically strings and numbers in various data structures).

    For example, one piece of data is a list of all the speech in the game. The actual script varies in each game, but the class that uses that script doesn't. That data only needs to be accessed by that one class within the game, and sending the information as an argument in the constructors would be really messy.

    What I want to do is from these classes in a separate, common directory, I want to be able to access the data that's specific to each game.

    I'm hoping that there's an easy, OOP way to do that.
    Last edited by Jezzamon; 12-31-2011 at 06:46 PM.

  4. #4
    Senior Member guardiankitty's Avatar
    Join Date
    Dec 2006
    Location
    Here
    Posts
    215
    Ah, I see.

    So you just want a way to 'hold data' that is specific to one version of the game in its own file for just one version of the game?

    Maybe keeping any data that is unique (and static/non-changeable) to each project (like all of the text/speech in the game) in an xml file would be the best way to achieve this.

    Then when you start up the game, just parse the xml file for that version, and populate your game with the proper data.

    Hope that is helpful- let me know if I am close to the right track for ya,

    ~gk >^.^<

  5. #5
    Member
    Join Date
    Nov 2009
    Posts
    33
    I would have considered an XML file, there are a lot of confusing combinations of arrays and objects so I would think the best way would be creating a blank class with the data stored as static variables. The XML file would be too verbose.

    So, only one or two classes need to access this data, so what I would want to do is have those classes be able to access the file directly, without the fla having to send the file or the file's contents to them.

    So like the class using the speech data would find the data file and then get the data from it itself.

    Is that possible?
    Last edited by Jezzamon; 01-01-2012 at 07:16 AM.

  6. #6
    Member
    Join Date
    Nov 2009
    Posts
    33
    Oh wow. After trying a few different things I tried accessing a class in the same folder as the fla file from one of these non-specific classes and you can just the same as if it's in the same folder!

    So it's actually just really easy, I just assumed I wouldn't be able to do it.

    Thanks for your help though... you gave me helpful information anyways! Plus I really want to play an underwater bowling game now!

Tags for this Thread

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