all groups > flash (macromedia) > august 2007 >
You're in the

flash (macromedia)

group:

shared object



shared object richhennosy
8/15/2007 8:58:20 PM
flash (macromedia): I have a series of movie clips on the right side of the stage. I have a grid
set up with a timeline for the user to drag the clips into the timeline. After
all of the clips are arranged in order, I need the user to be able to press a
play button and have all of the clips play in the order that they dragged them
to the timeline. I have seen this done, but don't know how to make it happen.
Here is a sample of my swf file. http://www.bigredrooster.com/ftp/loader5.swf

See my code attached. It allows the user to "save" the postion of the clips
after they have arranged them.

Any direction or advice is appreciated. (Actionscript 2.0)

Thanks,
Rich

stop();
var btnAr:Array = new Array(lucy_mc, jd_mc, nike_mc);
var goto_ar:Array = new Array(2, 3);
var HotSpots:Array = new Array(hotspot1_mc, hotspot2_mc, hotspot3_mc,
hotspot4_mc, hotspot5_mc, hotspot6_mc, hotspot7_mc, hotspot8_mc, hotspot9_mc,
hotspot10_mc, hotspot11_mc, hotspot12_mc);
for (var i = 0; i<btnAr.length; i++) {
btnAr[i].onPress = function() {
startDrag(this);
};
btnAr[i].ivar = i;
btnAr[i].onRelease = function() {
var drag:Boolean = true;
stopDrag();
for (var j = 0; j<HotSpots.length; j++) {
if (this.hitTest(HotSpots[j])) {
if (drag) {
gotoAndStop([goto_ar[this.ivar]]);
this._x = HotSpots[j]._x;
this._y = HotSpots[j]._y;
}
}
}
};
}
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(32)) {
lucy_mc.play();
}
if (Key.isDown(16)) {
lucy_mc.stop();
}
};
Key.addListener(keyListener);


mySharedObject_so = SharedObject.getLocal("myCookie");
saveButton.onRelease = function() {
mySharedObject_so.data.myXlucyposition = lucy_mc._x;
mySharedObject_so.data.myYlucyposition = lucy_mc._y;
mySharedObject_so.flush();
mySharedObject_so.data.myXnikeposition = nike_mc._x;
mySharedObject_so.data.myYnikeposition = nike_mc._y;
mySharedObject_so.flush();
mySharedObject_so.data.myXjdposition = jd_mc._x;
mySharedObject_so.data.myYjdposition = jd_mc._y;
mySharedObject_so.flush();

};
loadButton.onRelease = function() {
lucy_mc._x = mySharedObject_so.data.myXlucyposition;
lucy_mc._y = mySharedObject_so.data.myYlucyposition;
nike_mc._x = mySharedObject_so.data.myXnikeposition;
nike_mc._y = mySharedObject_so.data.myYnikeposition;
jd_mc._x = mySharedObject_so.data.myXjdposition;
jd_mc._y = mySharedObject_so.data.myYjdposition;

};
Re: shared object dzedward
8/15/2007 10:54:04 PM
this should get you started. at the end of each movie clip(lucy_mc, jd_mc)
place a stop(); and a _global.finished = true or _global.finished2 = true, and
so on... then use this code.. the problem right now is, the interval is firing
so fast, that when it receives the information that one is true, and it grabs
the frame out of the new Array, it goes to it, plays, but the interval fires
again and gives a new value, so it jumps to the next one... I'll work on it
more tomorrow, but this should give you a starting point to mess with. you
should have a play button on stage with instance name of play_btn. Also, it is
going to play in order they are snapped to hotspot, so we'll have to work on
something that only allows the hotspots enabled property in order, or a way to
cycle the array for which one was first..

stop();
var btnAr:Array = new Array(lucy_mc, jd_mc, nike_mc);
var goto_ar:Array = new Array(2, 3, 6);
var playAr:Array = new Array();
var HotSpots:Array = new Array(hotspot_mc, hotspot2_mc, hotspot3_mc,
hotspot4_mc, hotspot5_mc);
for (var i = 0; i<btnAr.length; i++) {
btnAr[i].onPress = function() {
startDrag(this);
};
btnAr[i].ivar = i;
btnAr[i].onRelease = function() {
var drag:Boolean = true;
stopDrag();
for (var j = 0; j<HotSpots.length; j++) {
if (this.hitTest(HotSpots[j])) {
if (drag) {
playAr.push([goto_ar[this.ivar]]);
this._x = HotSpots[j]._x;
this._y = HotSpots[j]._y;
}
}
}
};
play_btn.onRelease = function() {
_global.finished = false;
_global.finished2 = false;
_global.finished3 = false;
_global.indeX = Number(0);
gotoAndStop(playAr[0]);
wait = setInterval(waiting, 300);
function waiting() {
if (finished) {
gotoAndStop(playAr[indeX++]);
} else if (finished2) {
gotoAndStop(playAr[indeX++]);
} else if (finished3) {
gotoAndStop(playAr[indeX++]);
}
}
};
}
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(32)) {
lucy_mc.play();
}
if (Key.isDown(16)) {
lucy_mc.stop();
}
};
Key.addListener(keyListener);
Re: shared object clbeech
8/15/2007 10:55:38 PM
Hey Rich, I'd been following along with your other problem with the hotSpots
also :) I was just thinking that you could do this in another array, instead
of using a SharedObject, although you certainly can do it that way. But
still, you could just replace the index of an array that's matches the position
of the HotSpots, then if you would like the user to be able to 'come back' at
another time and play thier move that's one thing, and you could put the whole
array into one SO (at the very least you could iterate them into SO variables).
This way, once the array is constructed, the 'player' grabs the value from
there locally. Also if/when you bring it back in from an SO you can then push
the values into the array.

Just a thought. (PS. I do like SharedObjects though :)
Re: shared object rhennosy
8/16/2007 1:32:40 AM
clbeech,

It has been about 4 years since I have worked in Flash. I don't have a good
enough understanding of how all this works to execute what you are talking
about. I take tutorials and post messages each step along the way. I learn a
little each time. Hopefully by the time I get this project done, I will have a
good enough understanding to see where I could be more efficient. Right now I
am not there, but I am having fun getting back into it. I will read up on
Arrays and Shared Objects though and see what I can figure out. Maybe I will
have some questions after I learn a little more. Thanks for the tip.
Re: shared object clbeech
8/16/2007 2:43:04 AM
Rich, I think you're doing great, on a complex project here. Keep your chin up
:)

I was still typing as dzedward posted (he's so fast), He has done just what I
was talking about here and create some arrays to store the sequences. Don't
worry you're soing just fine.

Note about SharedObjects: They're great for storing info on the users
computer, kind of like cookies. but we usually want to use them for long term
storage of things like user prefs or bookmark kind of stuff. they would work
for this, but like we've been disscussing, better to use an array for the short
term, then maybe push it into a SO.
Re: shared object dzedward
8/16/2007 6:17:18 PM
okay, I worked out the kinks.. there is still one thing that needs to be
address, and I see there are two solutions.. 1) You have a message that says
only place them in order you want them to play starting with 1 and going from
there (1, 2, 3, etc).. 2) Hopefully someone else will want to work that out,
because this is as far as I go without payment.
http://www.imediapro.com/damonTesting/test/loader8.zip.
http://www.imediapro.com/damonTesting/test/loader8.swf. Open it up and study
what I did, open the buttons' corresponding Movie Clip and look at the last
frame to understand where "finished", "finished2", etc., is coming from. Good
Luck.
Re: shared object I H8 UM
8/17/2007 4:05:05 AM
dzedward and clbeech:

I pasted your code and everything works as I asked. It might be a good time to
explain the project in full detail. You may want to jump off at this point. I
appreciate your help in getting this far. But since you have taken an interest
in helping me, I think I should give you all the details of what I am trying to
create. I think you are answering my questions, but I may not be asking the
right questions. When all is said and done, you may wish I had given you all
the info upfront, because you would have done things differently.

I am building 30-40 external flash movies (swfs) that all of the sales reps
will use. I am trying to create an application that allows them to choose the
stories they want to tell, depending on the audience, in the order they want to
tell them. The drag and drop application is a way of them previewing and
loading the stories in a custom order to show to perspective clients. There
will be a list of 30-40 movie clips that they choose up to 12 to show. Before a
presentation, they would drag and drop the clips in order of play. With all of
the clips in order, they could then press play, the movies would start playing,
in full screen, in order with stops.

That is about it. I think we are almost there. Here are some problems I am
having.

1. Playing external swf files. Controlling them is where I am having trouble.
All of my stops vanish when they are loaded into a timeline. I have embedded
the clips while I work through it. That is also why the key listener is there,
to control a movie clip placed in the lucy_mc. I don't think it is going to
work though, because several movie clips will have nested movie clips that will
need to be stopped and started, not just lucy_mc.

2. I liked it when the movie clips played in the gray box in the upper left
corner when dropped onto a hotspot. This allows the presenter to preview the
clip and decide where to place it. It would also work if the large gray box
were the preview hotspot, and the other hotspots were used to create the order.

3. The current play button plays all of the movies in the gray box instead of
full screen. I have tried putting fscommand("fullscreen", "true"); at the
beginning of my clips, but that just takes my whole application grid to full
screen. (I think this goes back to my problem controlling external swf files.)

4. The current play button plays all of the movies without the stops. The
stops are speaking points and need to be there. (If these are controllable
external swf files, that may not be a problem.)

You have both helped me get very far along on this project and I really do
appreciate it and hope you want to keep going to see the final result. I think
it is doable, I just have to keep at it and keep asking questions.

Thanks,
Rich


Re: shared object dzedward
8/17/2007 2:26:08 PM
controlling the external SWF file is no problem, I would suggest loading them
in using the MovieClipLoader class so you can display some sort of preloading
activity by using the onLoadProgress event... You have two conflicting ideas
here, you want them to play full screen, but you want them to play in the
'grey' square as well... You need to make a decision here... This might help:
You wont be able to only display the 'preview' in full screen mode, unless you
shoot it into a pop up using javascript. What I have givin you will work for
the external files as well, just put the _global.finished at the end of their
timelines, and it will pick it up from the main SWF... you can put that _global
variable inside a setInterval function to have a delay, as you call, 'speaking
points'...
Re: shared object richhennosy
8/17/2007 3:01:56 PM
Re: shared object dzedward
8/17/2007 3:03:38 PM
Re: shared object richhennosy
8/20/2007 5:40:04 PM
Re: shared object dzedward
8/20/2007 5:45:42 PM
: (ps: to bad, that was some pretty neat scripting we had going)

stop();
var btnAr:Array = new Array(lucy_mc, jd_mc, nike_mc);
var goto_ar:Array = new Array(2, 3, 6);
var HotSpots:Array = new Array(hotspot_mc, hotspot2_mc, hotspot3_mc);

for (var i = 0; i<btnAr.length; i++) {
btnAr[i].onPress = function() {
startDrag(this);
};
btnAr[i].ivar = i;
btnAr[i].onRollOver = function(){
gotoAndPlay([goto_ar[this.ivar]]);
};
btnAr[i].onRollOut = function(){
gotoAndPlay(1);
};
btnAr[i].onRelease = function() {
var drag:Boolean = true;
stopDrag();
for (var j = 0; j<HotSpots.length; j++) {
if (this.hitTest(HotSpots[j])) {
if (drag) {
this._x = HotSpots[j]._x;
this._y = HotSpots[j]._y;
}
}
}
};
}
var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
if (Key.isDown(32)) {
lucy_mc.play();
}
if (Key.isDown(16)) {
lucy_mc.stop();
}
};
Key.addListener(keyListener);
Re: shared object richhennosy
8/20/2007 6:34:40 PM
Re: shared object dzedward
8/20/2007 6:48:29 PM
AddThis Social Bookmark Button