PDA

View Full Version : Simple OOP concept please :)


Sandcode
08-30-2011, 07:21 PM
Hello community

I have this simple project (well at least in conception :P) where I want to present a serie of items from a database (no problem here reaching my XML from my DB) and make them appear in front of us with an angle and allow us to scroll through them indefinitly.

I have a picture showing what I have done up to now. But all I have manage to do is load some 30 items (but only 12 can be shown on screen wich is what I want) and I am able to scroll through them but not indefinitly, so at one point nothing shows when I keep scrolling cause I didn't figure how to loop through them on screen.

The purpose is to show items people could bet on, the goal is to give the feeling there is always more item when all will be done is loop cycle through them.

I will attach my code too so you guys can see what I have done if you want but all I am really looking for is ideas.

From a simple projection, I populate the screen with a FOR loop with ItemHolders (I thought I'd give it some external class for the holders if I wanted to better manage my holders independently from my MAIN.as code, i.e. the style of my itemsholders) and they have a simple MOUSE_DOWN function that allows us to scroll them but when I reach the end, nothing more shows up and I don't know how to loop back at the beginning and in both directions (if I keep going down or if I keep going up, I wish them to loop).

I thought about 4 rows of MovieClip to update from an array maybe but I don't know how to approach the update method. I think arrays is a good part of this management but I'm no wiz with arrays though I'm working on it.

Ok well, any ideas is appreciated,

tks for your time and happy coding all !

PS : well I couldn't include the FLA but there's only my stage set-up and a link to my Main.as

Sandcode
09-03-2011, 11:08 PM
I have finally worked my way through my previous situation and am now exposing my thoughts hoping it might help.

Situation : I wanted to be able to scroll indefinitly through a list of item on stage ( in a fancy perspective :) from my DB and be it flexible enough to accomodate changes such as in number of rows and column of item on stage and the proportion they use on the stage, the distance between the rows and so on.

The hardest part (to me) was to manage infinite adjustable scrolling of items. I will spare all the failed attempts and get to my present solution. By no mean is my process proving to be efficient, it's only working and that's enough for me right now :)

First, I imported my xml list of item from my DB and populated an xmlList with the childrens. Then I populate an array with numbers as many as my xmlList.lenght. Now I can use my array to access previous and next item in the list and change my array accordingly after my fetch.

Using 2 while loops I populate my stage with my items. My first while loop creates as many movieclip as my 'NumberOrRow' requires. Inside that while loop I use a function (a second while loop) that basicly creates as many 'itemsHolder' as my 'NumberOfColumns' requires (all positionning made using the stageWidth property times the 'stageProportion' required divided accordingly so everything get evenly displayed). All of this is added (addChild) to a screen sprite I created to apply my global fancy perspective :) (and easely manage the numerous properties, all actionscripted using external classes). I also applied a little AlphaSort() method in my first loop checking the position of all my 'NumberOfRow' movieclips to see if the are near the top and bottom edges of my stage and fade them accordingly.

I made a zone my on stage that I used for a MOUSE_DOWN event in order to trigger the moving of my items (by simply going throught my array of 'NumberOfRow' movieclips again and moving them accordingly to my mouse going up or down) and applying again my AlphaSort method but added one last method, a swapOnZDepth() method that simply gets trought my array of 'numberOfRow' movieclips and check if they reach a certain position to reset it to the top or bottom of my screen (that way limiting the number of objects on my stage compared to creating them all in the first place and have them spread out of visibility - 20 objects on stage is ok but 3000 items on stage might not be ok, so limiting the number of items loaded will surely help).

By simply following my array populated with the xmlList.lenght, I can load the top or bottom (next or previous) item very easely by checking the current position of my array of xmlList.lenght and switching my array after I checked that way the first position in the array always refer to he next item to load, if I load the next object, I shift()-push() my array of xmlList.lenght, if I load the previous, I pop unshift my array so that my first position in the array always represents the next child to load from my xmllist. That way, if I reach the end of xmllist of items, it goes back to the beginning simply by following the positionning of my array associated with it (and by association, I only mean that if I have 12 items in my xmllist, my array wil have 12 numbers from 0 to 11 that represents the 12 childs of my xmllist so I can access my xmllist using - new ItemHolder(itemArrayCounter[0]), it will always access the 0 position because we will always change the array up or down when we are done reading from it, therefore the 0 position in the array is always updated to the next to load.

That's broadly my current approach. I marely wrote this answer to myself hoping it might give ideas to anyone (prolly beginners :P) who is working a similar situation.

I wish you all happy coding time :D