Loading AS "on the fly"

  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

First, I know that included actionscript files are loaded at compile time and cannot be included on the fly, but I have a need to be able to swap out some actionscript arrays arbitrarily.
I'm building a tilemap display for a game, and basically, it's a swf with about 300 tile images in the library, and a bit of actionscript to parse a large array and display the map. The game will contain many individual maps. I can compile the map display movie and have it reload each time the map changes, but since the movie is kind of large (271k because of the image data) what I would prefer to do is just change out the actionscript array and redraw the map, since they all use the same tile data.

Is there a way I could create small dummy movies with just the array data in them, load those movies into the main movie and still access the array data from the main movie? I have tried doing this already, but can't seem to access the data. I suspect it's a pathing issue, since i still haven't fully grasped flash pathing yet.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

why don't you put the array data in one or multiple xml files and include that as your game runs?

However, your dummy clip idea should work. Your right the path is probably the issue.

Its always a good idea to make a parent clip to load your clip into. When you use something like loadMovie("filename", "target") your new clip replaces the "target" clip but maintains its name. so If I load a clip into a clip on the main timeline called "container_mc" the path to "arrayName" in the loaded clip would be

_root.container_mc.arrayName[0];

Hope that helps
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

The dummy clip method doesn't seem to be working. Here's what I did. If you can see anything wrong with it, please let me know.
1. Created a new movie, pasted the array data into the actions area, and exported it as map1.swf.
2. In my main movie, I created a new movieclip, and named it mapData and dragged it to the stage. (I also tried using createEmptyMovieClip() to no avail)
3. in the actions for the main movie, I added loadMovie ( "map1.swf", "mapData" );
4. In the loop that actually draws the map, I'm trying to reference the data using _root.mapData.map[i][j], but it doesn't draw anything.

I have a feeling I'm going to have to resort to xml, but I really don't want to do that because the xml formatting will take take up more space than the actual map data.
The map is just a 100x100 array of integers. I really do not want to have to wrap every damn element in an opening and closing tag just to get it to play nice with flash. It's overkill.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

hahaha, interesting. I am working on a tile based game as well. So far i created a map editor with save/load options (in a text file ... of course, using server side script ... though it would've been much easier to do it in another language like c++ or c# but i wanted to test my flash knowledge :P) and the game part in which i load the tiles and i have a character that you can control to walk and jump on the tiles.
If you're interested in what i done so far, add my messenger id to your list.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

well, mine isn't fully flash. I'm just using flash for some of the heavier functions. The rest of it is php/ajax. You can see the old version here http://www.kgreene.com/rpg. I'm basically rewriting the entire UI right now.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

so i see, yours is more like a zelda tile based game.
My game will be more like a quest ... if you know the old z80 Dizzygames.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

Exactly. I prefer to compare it to the old Ultima series, but that's mostly because that's what I grew up on. I've never played Zelda intentionally :)

That screen shot you linked to is Treasure Island Dizzy, isn't it?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

oooh ... you know the old Dizzy collection? :D
yes, that's treasure island dizzy. Loved the Dizzy serie ... like 10 -14 years ago :D
About the map, here's what i did.
a XML file with all the tiles that can appear inside a map:
i.e.
Code: [ Select ]
<Categories>
    <Category ID="0" Name="Earth"></Category>
    <Category ID="1" Name="Fire"></Category>
    <Category ID="2" Name="Air"></Category>
    <Category ID="3" Name="Water"></Category>
</Categories>

<Items>
    <Item ID="0" CatID="0" Name="Grass1" Img="img/Ice1.jpg"></Item>
    <Item ID="1" CatID="0" Name="Grass2" Img="img/Ice2.jpg"></Item>
    <Item ID="2" CatID="0" Name="Grass3" Img="img/Ice3.jpg"></Item>
    <Item ID="3" CatID="0" Name="Grass4" Img="img/Ice4.jpg"></Item>


    <Item ID="4" CatID="1" Name="Fire1" Img="img/Ice5.jpg"></Item>
    <Item ID="5" CatID="1" Name="Fire2" Img="img/Ice6.jpg"></Item>
    <Item ID="6" CatID="1" Name="Fire3" Img="img/Ice7.jpg"></Item>
    <Item ID="7" CatID="1" Name="Fire4" Img="img/Ice8.jpg"></Item>
</Items>
  1. <Categories>
  2.     <Category ID="0" Name="Earth"></Category>
  3.     <Category ID="1" Name="Fire"></Category>
  4.     <Category ID="2" Name="Air"></Category>
  5.     <Category ID="3" Name="Water"></Category>
  6. </Categories>
  7. <Items>
  8.     <Item ID="0" CatID="0" Name="Grass1" Img="img/Ice1.jpg"></Item>
  9.     <Item ID="1" CatID="0" Name="Grass2" Img="img/Ice2.jpg"></Item>
  10.     <Item ID="2" CatID="0" Name="Grass3" Img="img/Ice3.jpg"></Item>
  11.     <Item ID="3" CatID="0" Name="Grass4" Img="img/Ice4.jpg"></Item>
  12.     <Item ID="4" CatID="1" Name="Fire1" Img="img/Ice5.jpg"></Item>
  13.     <Item ID="5" CatID="1" Name="Fire2" Img="img/Ice6.jpg"></Item>
  14.     <Item ID="6" CatID="1" Name="Fire3" Img="img/Ice7.jpg"></Item>
  15.     <Item ID="7" CatID="1" Name="Fire4" Img="img/Ice8.jpg"></Item>
  16. </Items>


And in the saved map i only keep the ID of the used item. Of course, that's why i made an editor too, i don't change them by hand :P
Code: [ Select ]
map0=-1;3;3;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;3;-1;-1;14;14;-1;-1;-1;-1;-1;-1;3;3;-1;-1;-1;-1;14;3;3;3;-1;-1;-1;-1;-1;-1;14;-1;-1;-1;-1;-1;-1;-1;-1;-1;6;3;3;-1;-1;-1;-1;-1;-1;6;-1;-1;-1;-1;-1;-1;-1;3;1;1;1;-1;3;3;3;-1;-1;6;-1;-1;-1;-1;-1;-1;-1;-1;3;-1;-1;-1;34;34;34;34;1;-1;-1;6;6;6;6;-1;-1;-1;-1;-1;-1;6;6;-1;-1;-1;-1;-1;-1;-1;-1;6;-1;6;6;-1;-1;-1;6;6;6;6;-1;6;
&mapattributes0=15;0;0;15;15;15;15;15;15;15;15;15;15;15;15;0;15;15;0;0;15;15;15;15;15;15;0;0;15;15;15;15;0;0;0;0;15;15;15;15;15;15;0;15;15;15;15;15;15;15;15;15;0;0;0;15;15;15;15;15;15;0;15;15;15;15;15;15;15;0;12;0;0;15;0;0;0;15;15;0;15;15;15;15;15;15;15;15;0;15;15;15;0;0;0;0;0;15;15;0;8;0;0;15;15;15;15;15;15;0;0;15;15;15;15;15;15;15;15;0;15;0;0;15;15;15;0;0;0;0;15;0;
&mapImage0=img/bg.jpg
  1. map0=-1;3;3;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;-1;3;-1;-1;14;14;-1;-1;-1;-1;-1;-1;3;3;-1;-1;-1;-1;14;3;3;3;-1;-1;-1;-1;-1;-1;14;-1;-1;-1;-1;-1;-1;-1;-1;-1;6;3;3;-1;-1;-1;-1;-1;-1;6;-1;-1;-1;-1;-1;-1;-1;3;1;1;1;-1;3;3;3;-1;-1;6;-1;-1;-1;-1;-1;-1;-1;-1;3;-1;-1;-1;34;34;34;34;1;-1;-1;6;6;6;6;-1;-1;-1;-1;-1;-1;6;6;-1;-1;-1;-1;-1;-1;-1;-1;6;-1;6;6;-1;-1;-1;6;6;6;6;-1;6;
  2. &mapattributes0=15;0;0;15;15;15;15;15;15;15;15;15;15;15;15;0;15;15;0;0;15;15;15;15;15;15;0;0;15;15;15;15;0;0;0;0;15;15;15;15;15;15;0;15;15;15;15;15;15;15;15;15;0;0;0;15;15;15;15;15;15;0;15;15;15;15;15;15;15;0;12;0;0;15;0;0;0;15;15;0;15;15;15;15;15;15;15;15;0;15;15;15;0;0;0;0;0;15;15;0;8;0;0;15;15;15;15;15;15;0;0;15;15;15;15;15;15;15;15;0;15;0;0;15;15;15;0;0;0;0;15;0;
  3. &mapImage0=img/bg.jpg

where map0 -> first map (can continue with map1, map2 ... but this in my case or you can use this too to split a bigger map in smaller parts) -> holds the ID's of the items. -1 represents a free tile, with no image, only the background will be seen.
mapattributes0 -> holds the information for each tile, telling if the tile can be stepped through and from which way. 0 means a solid block, no access through it, 1 -> can pass from left, 2-> can pass from right, 4-> from top; 8->from bottom. Combinations of these can be made (adding them), so 1+2+4+8 = 15-> access from all sides -> this will be for the free tiles.
mapImage -> the map background (this is only my case for you can't have a huge background in your game)
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

Well, I got my xml working and can now swap out maps on the fly, but now I'm running into another problem.
My maps originally were 100x100, and that works fine, and loads quickly, so I decided to go larger, and built a map that is 100x200, and that loads fairly quickly as well. All in all, I'm pretty satisfied with the xml approach.

Here's what I've got so far: http://www.kgreene.com/rpg/new/
It's not hooked into the game yet, as I still don't have many of the interface features done. You can move around on the world, and there are no movement restrictions, such as not being able to walk on water. There also isn't a map for the area you start in (because it's not done yet). If you click on the map icon, you get the map for the second island. You can change islands by hitting the swap map button on the bottom of the interface.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

Incidentally, I have another question:
Can the _root movie be resized on the fly?
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

ye, but flash acts strange.
You can do it from javascript, creating a new flash object, using the swfobject.js file, with:
Code: [ Select ]
var fo = new SWFObject("FlashObjectSample.swf", "FlashObjectSample", "236", "134", "8.0.5", "#FF6600");
    fo.write("flashcontent");
  1. var fo = new SWFObject("FlashObjectSample.swf", "FlashObjectSample", "236", "134", "8.0.5", "#FF6600");
  2.     fo.write("flashcontent");

And either make the width & height as parameters for a js function, or use php to change them.
Anyway, the idea is to change only one dimension of the flash file, either the width or the height, and keep the other one the same as in the original flash file, in order to make it work correctly. Otherwise it will make a zoom of the stage instead of increasing the width or height.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

I got around that problem. I was noticing the zoom problem, so what I did was make the swf 1600x1200, then put it in a container div with overflow: hidden; and centered the movie in the div. Works pretty well.
The whole reason for this is i wanted users to be able to resize the map window to fit their preference.

The problem I'm running into now is clearing old movieClips when a new map is loaded. I have several large "outside" areas of the game, and when I switch to them, it clears the clips file. These areas are larger than the 1600x1200 stage.
I also have several "inside" areas, for shops and such. These areas are smaller than the 1600x1200 stage, and when I load them, overlay tiles from the previous map stick on the stage (though they don't move when the character does)

Here's the code I'm using to clear the old map tiles:
Code: [ Select ]
    for (var q in _root)
    {
        if (typeof(_root[q]) == "movieclip")
        {
            _root[q].swapDepth(99999);
            _root[q].removeMovieClip();
        }
    }
  1.     for (var q in _root)
  2.     {
  3.         if (typeof(_root[q]) == "movieclip")
  4.         {
  5.             _root[q].swapDepth(99999);
  6.             _root[q].removeMovieClip();
  7.         }
  8.     }

Do you see anything wrong with that, or perhaps know a better way to clear the stage? All the movie clips are in the root timeline.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

Nevermind. The problem was that when the drawmap function is called, it draws out all the tiles and all the overlays using different names in the attachmovie method. I changed the function to use the same name for all of them, and now it cleans up just fine.
Not sure why using different names on attached movie clips would cause remnants to be left behind, but oh well.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

the problem might be from the swapDepth method.
try only removeMovieClip without the swap, and see what happens.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

That's what I tried first. When that didn't work, I thought it was a depth issue, so I added that. Anyway, it works now.
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

how are created the movie clips that u want to remove?
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

it's a simple loop. There are some calculations on where the tile should go, but basically it looks like this:
Code: [ Select ]
z=0;
for ( y = startY; y < endY; y++ )
{
    for ( x = startX; x < endX; x++ )
    {
        newTile = _root.attachMovie("t"+_root.map_arr[y][x], "tile", z, {_x:x, _y:y, _width:64, _height:64});
        z++;
        newTile = _root.attachMovie("o"+_root.over_arr[y][x], "tile", z, {_x:x, _y:y, _width:64, _height:64});
        z++;
    }
}
  1. z=0;
  2. for ( y = startY; y < endY; y++ )
  3. {
  4.     for ( x = startX; x < endX; x++ )
  5.     {
  6.         newTile = _root.attachMovie("t"+_root.map_arr[y][x], "tile", z, {_x:x, _y:y, _width:64, _height:64});
  7.         z++;
  8.         newTile = _root.attachMovie("o"+_root.over_arr[y][x], "tile", z, {_x:x, _y:y, _width:64, _height:64});
  9.         z++;
  10.     }
  11. }

Originally, the second attachMovie call used "over" as the name instead of "tile".
That's when it was having problems cleaning them up (it would delete all the "tile" movieclips and leave all the "over" clips in place)
  • IceCold
  • Guru
  • Guru
  • User avatar
  • Posts: 1254
  • Loc: Ro

Post 3+ Months Ago

hmmm ... and if all your tiles are named tile ... how do you know in what tile is your character for colision detection? x, y calculation?
anyway, seems strange that it doesnt remove all of the movies just because they have different names. I have to try myself what happens.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

well, the game is an RPG, and is based on php. The flash is just the display part. The actual game mechanics are handled in php and javascript.
  • ScienceOfSpock
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1893
  • Loc: Las Vegas

Post 3+ Months Ago

IceCold wrote:
oooh ... you know the old Dizzy collection? :D
yes, that's treasure island dizzy. Loved the Dizzy serie ... like 10 -14 years ago :D


Incidentally, I found where you can download the Dizzy series. It's considered abandonware now :)

http://www.abandonia.com/genre.php?genre=arcade&page=2

Post Information

  • Total Posts in this topic: 20 posts
  • Users browsing this forum: No registered users and 18 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.