View Full Version : help with local shared object
Nitsuj99
05-15-2008, 04:16 AM
I want to use local shared object to save the frame the user is currently on by clicking a button
then when the user clicks another button, it loads the last frame they were on.
please can someone help?
inhan
05-15-2008, 04:26 AM
var so:SharedObject = SharedObject.getLocal("lastSession");
btn1.onPress = function() {
so.data.lastFrame = _root._currentframe;
so.flush();
};
lastStateBtn.onPress = function() {
_root.gotoAndStop(so.data.lastFrame);
};
Nitsuj99
05-15-2008, 06:00 AM
worked great! thanks
inhan
05-15-2008, 04:17 PM
Check documentation for further info, and don't forget to flush if you want that data to be saved instantly, otherwise it will be saved after that session.
D-flyer
05-21-2008, 10:02 AM
sorry to hijack this thread.
@inhan,
i am trying to store a movieclip reference like
menuItem.onRelease = goto;
menuItem.onEnterFrame = status;
function goto() {
//selectedMenuItem_so.data.menuSelected = this;
selectedMenuItem_so.data.menuSelected = "_level0.menu_mc.item0";//test
selectedMenuItem_so.flush();
}
function status() {
//without a reload
if (selectedItem != this) {
Tweener.addTween(this.menuItemBG_mc, {_color:0xADA98F, time:0.1, transition:"linear"});
}
//with a reload
if (selectedMenuItem_so.data.menuSelected == this) {
trace("We have a match: "+this);
Tweener.addTween(this.menuItemBG_mc, {_color:0xC55C7B, time:0.1, transition:"linear"});
}
}
inhan
05-21-2008, 10:23 AM
There's something critical there. You're adding a tween once every your frame rate in a second. Is that what you want? I think you might wanna delete the onEnterFrame in some case to stop it from executing again and again.
Did you open the SharedObject somewhere prior to this code, like the following?
var selectedMenuItem_so:SharedObject = SharedObject.getLcal('something')
You can assign objects to a SharedObject, in other words you don't have to quote the mc name there, but if there's a case that subject matter mc might not be created by the time you're pushing its value to the SharedObject, then later use it like:
if (eval(selectedMenuItem_so.data.menuSelected)) == this) { etc.
Can you explain what you want this code to do exactly?
D-flyer
05-21-2008, 02:35 PM
@inhan, your are abosolute right.
- I just want to have a _selected state for a menu item, so i thought of using the onenterframe. i have to figure out where i should use
delete this.onEnterFrame;
- yes, i opened shared object
var selectedMenuItem_so:SharedObject;
selectedMenuItem_so = SharedObject.getLocal("selectedItem");
- what i am trying to do is a very simple menu with submenu. In the webpage i am using swf object and i have a div="flashmenu". Now the links in the flashmenu have as like getURL("link A","_self"); So the flashmenu will be loaded each time. That's why i want to use shared object so it reminds which menuitem is selected
inhan
05-21-2008, 06:52 PM
You don't need an onEnterFrame for that. All you need is create the SharedObject and ask for the last state, like...
menuItem.onRelease = goto;
// launch it first
var selectedMenuItem_so:SharedObject = SharedObject.getLocal("selectedItem");
// you can still make the previous one play its 'out' animation if you like
if (selectedMenuItem_so.data.menuSelected != undefined) {
var mc:MovieClip = selectedMenuItem_so.data.menuSelected;
// Tweener.addTween(mc.menuItemBG_mc, {etc etc.
}
function goto() {
if (selectedMenuItem_so.data.menuSelected =! this) {
selectedMenuItem_so.data.menuSelected = this;
selectedMenuItem_so.flush();
Tweener.addTween(this.menuItemBG_mc, {_color:0xADA98F, time:0.1, transition:"linear"});
} else {
Tweener.addTween(this.menuItemBG_mc, {_color:0xC55C7B, time:0.1, transition:"linear"});
}
}
D-flyer
05-22-2008, 11:01 AM
aarrghh,
i am thinking in loops, anyway now when i trace selectedMenuItem_so.data.menuSelected
i just get
Cookie menuItem: false
and not the instance name which is set with function goto()??
var selectedMenuItem_so:SharedObject = SharedObject.getLocal("selectedItem");
trace("Cookie menuItem: "+selectedMenuItem_so.data.menuSelected);
function generateMenu(container, x, y, name, depth, thisArray) {
//menuArray.trace();
var curr_item:MovieClip;
var curr_menu = container.createEmptyMovieClip(name, depth);
for (i=0; i<thisArray.length; i++) {
curr_item = curr_menu.attachMovie("menuItem", "item"+i, i);
curr_item._x = x;
curr_item._y = y+i*40;
curr_item.menuText.autoSize = true;
curr_item.menuText.multiline = false;
curr_item.menuText.condenseWhite = true;
curr_item.menuText.text = ucfirst(thisArray[i].name);
curr_item.menuItemBG_mc._width = Math.floor(curr_item.menuText._width)+15;
curr_item.submenuID = thisArray[i][0].submenuID;
curr_item.gotoURL = thisArray[i].gotoURL;
curr_item.name = thisArray[i].name;
curr_item.submenuName = thisArray[i][0].submenuName;
curr_item.menuID = i;
curr_item.onRollOver = over;
curr_item.onRollOut = out;
curr_item.onRelease = goto;
//curr_item.onEnterFrame = status;
//setStatus(curr_item);
}
}
function goto() {
submenuID = this.submenuID;
submenuName = this.submenuName;
name = this.name;
if (submenuName == "submenu") {
generateMenu(menu_mc, 5, beginY+20, "submenu_mc", 1000, menuArray[submenuID]);
submenu_so.data.submenuID = submenuID;
submenu_so.data.submenuName = submenuName;
submenu_so.data.name = name;
submenu_so.flush();
menu_mc.attachMovie("divider_mc", "divider_mc", menu_mc.getNextHighestDepth());
menu_mc.divider_mc._x = 10;
menu_mc.divider_mc._y = 326;
} else {
closeSubmenus(name);
}
trace("MC is: "+this);
/*if (selectedItem != this) {
trace("Now another");
Tweener.addTween(this.menuItemBG_mc, {_color:0xC55C7B, time:0.1, transition:"linear"});
selectedItem = this;
}*/
if (selectedMenuItem_so.data.menuSelected =! this) {
selectedMenuItem_so.data.menuSelected = this;
selectedMenuItem_so.flush();
Tweener.addTween(this.menuItemBG_mc, {_color:0xADA98F, time:0.1, transition:"linear"});
} else {
Tweener.addTween(this.menuItemBG_mc, {_color:0xC55C7B, time:0.1, transition:"linear"});
}
//getURL(this.gotoURL, "_self");
}
inhan
05-22-2008, 04:27 PM
I don't know what 'thisArray' holds but to query it with 'this' as an instance you should have references to instances in the array and not string names. I don't know the array so I can't guess.
You might wanna post a simplified (please, simplified without any irrelevant code) file so that we can see what's really happening.
Nitsuj99
05-28-2008, 01:24 AM
One more question about this,
How can I have when you reach a certain frame a button becomes visible in another frame and stays and then it saves its visibility and loads it right away after you open the projector?
inhan
05-28-2008, 01:40 PM
Set a variable for the visibility, flush it in the SharedObject, read it in the SharedObject and assign it to that instance at the beginning of your movie (frame#1).
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.