AS3 saving from a timeline to a sharedObject (possible to place in an array) - arrays

I was hoping someone could offer a simple solution. I am trying to save a 'labeled' frame on the timeline by storing it as a SharedObject.
The user can flip between various different backgrounds on the stage by clicking a button - button one corresponds to background one, background 2 corresponds to btn two and so on... For your reference these backgrounds are stored in a sub timeline in a movieClip. Any tips on how to get this to store..?
I'm open to new theories as I'm not having a lot of success saving from the movieClip on the time line.
I have already posted a question similar to this but I was wandering if it was possible to store these frames in an array? Array1 = image1 Array2 = image2 and so making it easier to store. I'm guessing I would need to make a loadermodule to store these images on the stage as well.
Thanks
// SAVE FUNCTIONS ---------------------------------------
//---------------------------------------------------
//---------------------------------------------------
var mySO:SharedObject = SharedObject.getLocal("iDesign");
bones_mc.x = mySO.data.my_x;
bones_mc.y = mySO.data.my_y;
if (!mySO.data.my_y) {
bones_mc.x = 424;
bones_mc.y = 119;
}
//----
save_btn.addEventListener (MouseEvent.CLICK, clickersave);
function clickersave (e:MouseEvent):void {
mySO.data.my_x = bones_mc.x;
mySO.data.my_y = bones_mc.y;
mySO.data.mybut_x = btrfly_mc.x;
mySO.data.mybut_y = btrfly_mc.y;
mySO.data.mytig_x = tiger_mc.x;
mySO.data.mytig_y = tiger_mc.y;
mySO.data.mybow_x = pink_bow_mc.x;
mySO.data.mybow_y = pink_bow_mc.y;
mySO.data.myblkbow_y = pink_bow_mc.y;
mySO.data.myblkbow_x = pink_bow_mc.x;
// tears saved - - - - - - -
mySO.data.mytear_drop_mc_three_x = tear_drop_mc_three.x;
mySO.data.mytear_drop_mc_three_y = tear_drop_mc_three.y;
mySO.data.mytear_drop_mc_one_x = tear_drop_mc_one.x;
mySO.data.mytear_drop_mc_one_y = tear_drop_mc_one.y;
mySO.data.mytear_drop_mc_two_x = tear_drop_mc.x;
mySO.data.mytear_drop_mc_two_y = tear_drop_mc.y;
mySO.data.mytear_drop_mc_four_x = tear_drop_mc_four.x;
mySO.data.mytear_drop_mc_four_y = tear_drop_mc_four.y;
mySO.data.myframe = caseSwapper.currentFrame;
trace(caseSwapper.currentFrame)
mySO.flush ();
}
//caseSwapper.currentFrame = mySO.data.myframe;
tear_drop_mc_three.x = mySO.data.mytear_drop_mc_three_x;
tear_drop_mc_three.y = mySO.data.mytear_drop_mc_three_y;
CODE ADDED TO MAKE THE TIMELINE SAVE - - - - - - - - - -
// applied to the clickersave function
mySO.data.myBgFrame = 2;
mySO.flush ();
}
if (mySO.data.myBgFrame){
caseSwapper.gotoAndStop(mySO.data.myBgFrame);
}

Not sure I understood exactly what you mean, but if you use click on button1 for BG1, in the click function you could write:
mySO.myBgFrame = 1;
mySO.flush ();
and than, when you need to set the saved BG:
if (mySO.myBgFrame){
bgMovieClip.gotoAndStop(mySO.myBgFrame);
}
Is this what you need?

Related

React and Global state(reactn)

I am currently using react and manage a global state with reactn (https://github.com/charlesStover/reactn).
I have to work with "SVG" and be able to make diagrams in the future.
I would like for each rectangle that I create,
and update the x and y coordinates.
my rectangles are stored in a global state => index.js
SetGlobal({rectangles : []})
I just need to set the array rectangles with indexes of the current rectangle without going through the copy of the whole array
const allRectangles = [...rectangles];
allRectangles[index].x = allRectangles[index].x - diffX;
allRectangles[index].y = allRectangles[index].y - diffY;
allRectangles[index].cercle1.x = allRectangles[index].cercle1.x - diffX;
allRectangles[index].cercle1.y = allRectangles[index].cercle1.y - diffY;
allRectangles[index].cercle2.x = allRectangles[index].cercle2.x - diffX;
allRectangles[index].cercle2.y = allRectangles[index].cercle2.y - diffY;
allRectangles[index].coords.x = e.pageX;
allRectangles[index].coords.y = e.pageY;
setRectangles(allRectangles);
I have to do this kind of exercise but with a global state
https://codesandbox.io/s/0xo7y0wolv
I do not know if I made myself understood, it's still new to me.

Swift - Update and store position of a multiple programmatically created buttons

I have a button which creates other buttons based on the class Clip seen below. Those newly created buttons are added to an array and stored in a plist.
class Clip: Encodable, Decodable {
var name: String = ""
var xCoordinate: Int = 100
var yCoordinate: Int = 300
// more parameter will be added later on e.g color, scale etc..
}
Each button can be moved around the view and the new x & y coordinates are stored in a plist.
#objc func handlePan(sender: UIPanGestureRecognizer){
let uIViewSelected = sender.view!
switch sender.state {
case .began, .changed :
moveViewWithPan(view: uIViewSelected, sender: sender)
break
case .ended:
//Finds the position when the button is no longer being dragged
let x = Int(uIViewSelected.center.x)
let y = Int(uIViewSelected.center.y)
//clipArray[0] need to be the corresponding clicked button e.g clipArray[2]
clipArray[0].xCoordinate = x
clipArray[0].yCoordinate = y
saveData()
break
default:
break
}
}
The above works only if I create one button. When more buttons are added, the above lines only change the first clip from the array. I need a way to update the value to the correct button clicked.
How can identify the array position of the click button as I am creating all them programmatically? At the moment I am placing at value 0 of the clipArray.
clipArray[0].xCoordinate = x
clipArray[0].yCoordinate = y
I am not even sure if using a plist is the best way to store the buttons in the first place.
Any help or documentation would be much appreciated.
Thanks
Following from dfd response, I added tags to each button which are created and it solved the issue for now.
let x = Int(uIViewSelected.center.x)
let y = Int(uIViewSelected.center.y)
//clipArray.append(clip)
var tagNo = uIViewSelected.tag
clipArray[tagNo].xCoordinate = x
clipArray[tagNo].yCoordinate = y

image array and .src - image not changing

I have created an array which is being used to store a series of .gif images and I'm just trying to test everything out by using document.getElementById to change the .src value but when I change it and load the page the image stays the same as it was before.
function setImage()
{
var images = new Array();
images[0] = anemone.gif;
images[1] = ball.gif;
images[2] = crab.gif;
images[3] = fish2.gif;
images[4] = gull.gif;
images[5] = jellyfish.gif;
images[6] = moon.gif;
images[7] = sail.gif;
images[8] = shell.gif;
images[9] = snail.gif;
images[10] = sun.gif;
images[11] = sunnies.gif;
images[12] = whale.gif;
var slots = new Array();
slots[0] = document.getElementById("slot" + 0);
slots[1] = document.getElementById("slot" + 1);
slots[2] = document.getElementById("slot" + 2);
slots[0].src = "snail.gif";
document.getElementById('slot0').src = images[0];
alert(images.length);
}
I can't understand why the image wont change, but I know it has to be something very simple. I've been wasting hours trying to get this one thing to change but nothing works. can anyone please point out the error of my ways?
There are a couple of issues with your code:
Your filenames need to be Strings, so they'll have to be quoted (also you can simplify the Array creation):
var images = ['anemone.gif', 'ball.gif', 'crab.gif', 'fish2.gif', 'gull.gif', 'jellyfish.gif', 'moon.gif', 'sail.gif', 'shell.gif', 'snail.gif', 'sun.gif', 'sunnies.gif', 'whale.gif'];
Also make sure you are getting your slot-elements right, quote all the attributes like:
<img id="slot0" class="slot" src="crab.gif" width="120" height="80">
When you create the slots-Array you can do it like this (no need to concat the ID string):
var slots = [document.getElementById('slot0'), document.getElementById('slot1'), document.getElementById('slot2')];
Finally make sure you call your function when the document has loaded / the DOM is ready. If you don't want to use a framework like jQuery your easiest bet is probably still using window.onload:
window.onload = setImage; //note that the parens are missing as you want to refer to the function instead of executing it
Further reading on Arrays, window.onload and DOMReady:
https://developer.mozilla.org/de/docs/DOM/window.onload
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array
javascript domready?

flash as3 - how to get next element in an array

I have an array of five possible videos that can play called videos, and an array of active videos called activeVideos. When one video finishes playing, I need to take its index, find its location in the activeVideos array, and get the next value in the array. If there are no more values in the array, I need to grab the first value. So essentially:
activeVideos = [0,1,3]
videos = [video1, video2, video3];
function nextVideo(e:Event){
var curIndex = videos.indexOf(currentVideo);
var next = activeVideos.find(curIndex).nextValue // pseudo-code - need to locate the position of the current video within the active array, select the next element, and call show video.
showVideo(videos[next]);
}
How do I do this?
activeVideos = [0,1,3]
videos = [video1, video2, null, video3];
function nextVideo(e:Event){
var curIndex = videos.indexOf(currentVideo);
var next = activeVideos[curIndex+1] || activeVideos[0];
showVideo(videos[next]);
}
function nextVideo(e:Event){
var curIndex = videos.indexOf(currentVideo) + 1;
var nextVideo = curIndex >= videos.length ? videos[0] : videos[curIndex];
showVideo(nextVideo);
}
Maybe you can try this at home, I must confess my flash might be a bit rusty since the advent of the html5, css3 + js hype :)
nextIndex = -1;
nextIndex = ( (curIndex+1 == videos.length) ? 0 : curIndex+1 );
if (nextIndex > -1){
var next = activeVideos[nextIndex];
// ... do your stuff
}

Finding New and Updated Pages in EpiServer

I have a requirement to display lists of newly-created and updated pages in our Episerver intranet - say the last ten of each. I've tried using FindPagesWithCriteria but this returns no results. Here's the code I've tried:
PageDataCollection recentPages;
PropertyCriteriaCollection criteria;
PropertyCriteria upperBound;
PropertyCriteria lowerBound;
criteria = new PropertyCriteriaCollection();
upperBound = new PropertyCriteria();
upperBound.Condition = CompareCondition.LessThan;
upperBound.Type = PropertyDataType.Date;
upperBound.Value = DateTime.Today.ToString();
upperBound.Name = "Created"; // Or Saved for updated pages
criteria.Add(upperBound);
lowerBound = new PropertyCriteria();
lowerBound.Condition = CompareCondition.GreaterThan;
lowerBound.Type = PropertyDataType.Date;
lowerBound.Value = DateTime.Today.AddDays(-7).ToString();
lowerBound.Name = "Created";
criteria.Add(lowerBound);
recentPages = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criteria);
I've also tried using the RecentlyChangedPagesFinder (as detailed here) - this returns some results, but when I try to use the set of results to build a PageCollection to databind into a PageList, again I get nothing output. And I can't see that I could use that for new pages, only updated ones.
The property name should be "PageCreated".
http://epiwiki.se/developing/properties/all-built-in-properties
You can also improve your FindPagesWithCriteria-syntax by going something like this:
var criterias = new PropertyCriteriaCollection
{
new PropertyCriteria()
{
Name = "SomeProp",
Type = PropertyDataType.PageType,
Value = "eh",
Condition = CompareCondition.Equal,
Required = true
},
new PropertyCriteria()
{
...
};
var pages = DataFactory.Instance.FindPagesWithCriteria(somePageLink, criterias);

Resources