|
-
Senior Member
[RESOLVED] [MX] Array Question
Hello, here is my question. I have 10 icons on the stage and I'm wanting to save their "x" and "y" postions to a sol file. This I know how to do. However I'm trying to make the code as efficient as possible. Which is my question; can I use an array to collect the coordinates data of each icon? Or do I have to write out the code for each one? I was hoping to have an array run setup and then a function run through appending the data to each button and moving on to the next. Something like this pseudo code:
Code:
myarray = newArray("btn1", "btn2", "btn3");
posx = getProperty(myarray, _x);
posy = getProperty(myarray, _y);
function save(){
Write sol file
myarray + posx + posy
}
Something along those lines, where I'm not writing out the same code for every button. If I need to clarify more please let me know. Thanks
Mo
-
Developing For Dunkets
for(i=0; i<=myArray.length; i++){
var so:SharedObject = new SharedObject("savePos");
so.data.pos[i] = myArray[i]
}
that should save everything stored in myArray to your so file. then to read it back
for(i=0; i<=myArray.length; i++){
myArray[i] = so.data.pos[i]
}
that should put the positions back into the array. You still have to store all the positions to the array and read them back out to set them.
-
Senior Member
mneil; man your saving my butt on this headache! I thank you. I tried the code you sent and I couldn't get it to work. I changed a few things and got it to work somewhat finally but ran into more problems. First let me do some explaining. As you may recall the buttons are not named btn1/btn2 they have destinct names btncontacts/btnsilent. I got the array to run through a list of the names and assign the approperiate attrib's to each button, so that was a plus. I even got the thing to write a sol file correctly I do believe but there is where to problem lies. Running it through a function as it is, it is constantly overwriting the sol file containing the previous buttons information. I've been messing with the fla for the last 3 hours trying to figure out a workaround and have thus far failed. I've attached the current fla file. Much thanks for all your aid!
Mo
Last edited by Mo1010427; 08-15-2007 at 07:07 PM.
-
Developing For Dunkets
Sorry, I didn't check what I wrote up above; but at least you got it to work. I'm going to take a look at your fla and I'll get back to you if I get anything.
-
Developing For Dunkets
I had to read your last post a couple of times but if I'm right you just need to use this in your save function:
function saveme(){
for(i=0; i<=myArray.length - 1; i++){
_root["myico"+i] = myArray[i];
_root["myico_x"+i] = getProperty(myArray[i],_x);
_root["myico_y"+i] = getProperty(myArray[i],_y);
datico = sharedobject.getLocal("abate");
datico.data.ico = _root["myico"+i];
datico.data.icox = _root["myico_x"+i];
datico.data.icoy = _root["myico_y"+i];
trace("myico= "+myico[i]+"X= "+myico_x[i]+"Y= "+myico_y[i]);
}
};
Then of course reverse that to load. I don't see where you are calling your save function. I know where you set it(obviously) but I don't see where you set it nor can I figure out where you might have it already. So, does it exist yet?
-
Senior Member
I'm going to try your code recommendations now. To answer your question; in the top right hand corner it says "Cookies: On Off". The "On Off" is a mc and the code in nested inside there. Frame 1 has the off setting and is going to ignore writting the sol file or clear the one that exists. This would reset the position of the icons/buttons. It's mostly to provide some ease of mind for people who aren't sure what cookies are. Frame 2 in "_root.mccookies" is calling the function in the main timeline to save to the sol file. I'll let you know what I can get to work.
-
Senior Member
mneil, I messed around for a bit using your code. It does work, but I am still getting the same problem. If you look at the sol file that is written it only records the last button in the array. The function says go until the lenght of the entries in the array. The problem is that the script to write the sol file is within that as well. So every time the function is running its cycle ....it's appending the "x" "y" position to the corresponding button, writting the sol file, then incrementing the [i] by 1. This is fine expect when you get to the part where it writes the sol file. Instead of appending to the file it's overwritting it. So all the ends up in the sol is the "x" "y" position of the last button "Safety". I hope that makes sense.
Last edited by Mo1010427; 07-25-2007 at 08:55 PM.
-
Flashmatics
hi what exactly are u trying to do... basically have a SharedObject record positions of the buttons once you click a save button and replace them in those positions when u reopen it?
If the above is what u need i can create a quick example for u..
-
Senior Member
Silentweed, that was basically what I was after. I knew how to do the SharedObject but I was trying to be as efficient with my coding as possible. Which is why I was thinking running an array would be the better way to go. In the end it was in a loop basically creating the sol file then incrementing by 1. This overwrote the previous saved sol file. I think I got it to work for the most part, just fighting with the fine tweeking; like trying to get it to clear the data stored when turned off or skipping the function if the button was off. It's gotten to the point where their is so much nested and scripted it's hard to keep up with what is calling what and what is doing what. If I get really stuck again though trust me I'll post here! Thanks
Mo
-
Developing For Dunkets
Sorry, I think all you had to do to fix that was put the sharedobject above the for loop. How far are you now?
function saveme(){
datico = sharedobject.getLocal("abate");
for(i=0; i<=myArray.length - 1; i++){
_root["myico"+i] = myArray[i];
_root["myico_x"+i] = getProperty(myArray[i],_x);
_root["myico_y"+i] = getProperty(myArray[i],_y);
datico.data.ico = _root["myico"+i];
datico.data.icox = _root["myico_x"+i];
datico.data.icoy = _root["myico_y"+i];
trace("myico= "+myico[i]+"X= "+myico_x[i]+"Y= "+myico_y[i]);
}
};
-
Senior Member
you know i've found that the serect to arrays is to set a defalt value to each slot in the array and then use spli to rewite each slot with the data i want the array to contain its easier to manage and understand than a looping array
-
Senior Member
calmchess; I've never seen the word "spli" before. Is that a program, acronym, or typo? At any rate I appreciate the assistance, and I would agree that looping arrays can be complicated to understand. Especially when 3 functions are calling the array to run a loop.
-
Senior Member
mneil, I decided that running the array might not work so hot. I tried several ways of going about making it work and none of them resulted in functioning properly. I read what you posted about putting the SharedObject outside the loop; that still resulted in the file being overwritten constantly. I just re-read your code now and I noticed something. Ok, I long coded mine out, each data spot in the SO (SharedObject) has a unique name. i.e.
datico.data.contacts_x = getProperty(_root.btncontacts._x)
datico.data.silent_x = getProperty(_root.silent._x)
ok, this way it works. It writes one file and all the information is saved in the respectful "data container" The thing I'm working on now is trying to clear the information if the "cookie" is turned off. So I tried this coding
datico.data.cleared = ""
all that did was append to the sol file the new data container - "cleared" Now like I was saying after re-reading your code. If you look you have:
datico.data.icox = _root["myico_x"+i];
This wouldn't work I don't think. The data container is remaining the same name, so each time the same container is being rewritten. I would need to have that name change as well within the array. I hope this makes sense. I'm going to try it out and see if I'm right as soon as I get the chance. I also uploaded the .fla as to where it stands currently. Thanks
Mo
Last edited by Mo1010427; 08-15-2007 at 07:07 PM.
-
Developing For Dunkets
you can delete the shared object completely with
datico.clear();
-
Senior Member
typo i meant split I am using a pda to respond sorry i will type on the keypad more slowly ....anyway i say using a "looping" array is bad because each time you call the array you are rewriting the enitire array but when you just change 1 slot of the array using split then you are coping the array and appending a specific slot also what keeps your looping array from over writing data that the user doesn't want changed for example what if they move 2 icons but not the third icon? doesn't your method overwrite the icon that didn't move? my thinking could be wrong so plz explain if you disagree with me .
-
Developing For Dunkets
Yes, the way I mentioned overwrites the icon that didn't move, but it just replaces it with the exact same information that is already there. It's a little repetitive, but there isn't a lot of info being stored. It's only 6 or 7 icons.
I do like your split idea though. I just only use that if I've got a ton of info.
-
Senior Member
ok so are you telling the icons where there postion is by saying
myico_x = myslot[0]; ??because if you are and the icon that you are positioning has a diffrent postion in the array if you are looping and I think that since you aren't storing alot of information a looping array isn't necessary but hey write it the way you want i just exploring other ideas....sorry to put my 2 cents in i won't be writing any code i should have probably just shut up.
-
Developing For Dunkets
It's not me who is trying to get the answer to this question solved. this is Mo1010427's post. All I did was add a loop to it to store the info so he wouldn't have to do it for 6 different icons. But, I never checked it in the first place, so ended up it was wrong. I'm not saying my way is the only way to do it, its just the quickest answer I came up with for Mo's question. So I don't care if you write the code or not, but you probably might want to to try and help they guy who needs the answer.
-
Senior Member
mneil, I did read about the clear() function and as far as I understood it is supported by MX2004 and above. That leaves me SOL (no pun intended) with MX or maybe it should be At any rate the brunt of the work is finished now I think and I GREATLY appreciate all your help. I messed around with the array more like I said I would try, and I still didn't get it to work quite right. It still wouldn't change the name for "data.namehere". So it was always overwritting. Not sure maybe able to be worked around or perhaps program limitation from old software. Either way it's irrelevant. I'll read up on the split method just so I get an undestanding of it. Never hurts to know alittle more about things. All in all though, I got the things I wanted working; working. Again I appreciate all the help I've recieved from you guys. I wouldn't have gotten it accomplished without ya. Thanks
Mo
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|