Hey everyone. I'm currently in the process of developing a game which allows you to customize the color (hue) of your character via a slider. What I would like to happen is: Upon clicking either Accept or Play, it will save the current hue of the image, navigating back to that page will load what was previously saved (hue), as well as when starting the game, it will replace the standard graphic with the previously saved image.
Below is the code I have right now that pertains to the image with a basic non-functioning properly saving and loading code:
import flash.events.KeyboardEvent;
// open a local shared object called "myStuff", if there is no such object - create a new one
var savedstuff:SharedObject = SharedObject.getLocal("myStuff");
Accept.addEventListener(MouseEvent.CLICK, SaveData);
PlayBTN.addEventListener(MouseEvent.CLICK, LoadData);
function SaveData(MouseEvent){ savedstuff.data.username = Sliders.Dino.MovieClip // changes var username in sharedobject savedstuff.flush(); // saves dataon hard drive
}function LoadData(event: MouseEvent)
{ if(savedstuff.size>0){ // checks if thereis something saved Sliders.Dino.MovieClip = savedstuff.data.username} // change field text to username variable
}
// if something was saved before, show it onstart
if(savedstuff.size>0){
Sliders.Dino.MovieClip = savedstuff.data.username}
What I have above is only saving the actual image, which is inside a movie clip names Sliders.
Below is the Class I am using that associates with the slider that changes the hue of "Dino".
package
{ import flash.display.Sprite; import fl.motion.AdjustColor; import flash.filters.ColorMatrixFilter; import fl.events.SliderEvent; publicclass Main extends Sprite { private var color:AdjustColor = new AdjustColor(); private var filter:ColorMatrixFilter; publicfunction Main():void { /* Required tocreate initial Matrix */ color.brightness = 0; color.contrast = 0; color.hue = 0; color.saturation = 0; /* Add Listeners function */ addListeners(); } private final function addListeners():void { colorPanel.hueSL.addEventListener(SliderEvent.CHANGE, adjustHue); } private final function adjustHue(e:SliderEvent):void { color.hue = e.target.value; update(); } private final functionupdate():void { filter = new ColorMatrixFilter(color.CalculateFinalFlatArray()); Dino.filters = [filter]; } }
}
Overall what I'm asking for is: How do I get it to save the current hue of an image by clicking a button, and then having that previously saved image be loaded upon reloading or clicking a button? To me, it doesn't seem like it should be too hard, but for some reason I can not grasp it.
Thanks in advance for reading this and for any assistance you have to offer!