all groups > flash actionscript > april 2005 >
You're in the

flash actionscript

group:

Passing data from one flash file to another


Passing data from one flash file to another BuenasHowdy
4/26/2005 12:00:00 AM
flash actionscript: Hello everyone -

Im in a jam and I need some help. Ill try to explain as best as I can so
please bare with me.

Essentially what I am trying to accomplish is to send data from one flash file
to another. I'm starting with a flash file that enables users to view image
thumbnails. The thumbs contain image info such as name, shoot location,
gallery name, etc. After selecting an image of their choosing, the original
flash file closes and a new flash file that essentially is the image details
page (where they can add a frame, matte, etc) opens. I would like to send the
image info from the first flash file to this newly opened details page (new
flash file). Is there a way to store these variables in memory and simply call
them up in the newly opened flash file? Please advise on the best approach.
If possible, would someone be kind enough to illustrate the proper method with
an example?

What im looking to accomplish here might be trivial for most of you, but Im
just starting out scripting with ActionScript and I could really use some
guidance/help right now.

Thanks in advance.
Re: Passing data from one flash file to another Captain James
4/26/2005 12:00:00 AM
If I understand you correctly, you can't do this in any simple way involving
Flash, since the moment you replace the base swf (_level0) by loading a new swf
in its place, you lose everything that had been inside that movie, including
data inside any sub-movies that had been loaded into _level0 before the
replacement.

I think the best route for you is not to replace _level0 in the first place.
Instead, create an empty movie clip (using _root.createEmptyMovieClip) -- or
several, if necessary -- and load things into those instead. That way, any
variables that exist on the _root level will remain available to every other
loaded movie.

Hope that gives you a place to start.
Re: Passing data from one flash file to another BuenasHowdy
4/26/2005 12:00:00 AM
Re: Passing data from one flash file to another LuigiL
4/27/2005 12:00:00 AM
Have a look at www.imagevuex.com. It's a sophisticated imagebrowser with
Flash-admin panel. If not an out-of-the-box solution for you, it's a great way
to learn how to build want you want in one Flash-file. Sending data to another
swf is possible by the way. There are several options but I would possibly use
a little PHP-script catching a variable from swf-1 and placing it in a FLASHVAR
in swf-2. Good luck!
Re: Passing data from one flash file to another BuenasHowdy
4/27/2005 12:00:00 AM
LuigiL -

I took a look at www.imagevuex.com - very nice. Thanks for the info.

Im still having problems getting the data to show up in my text fields,
though. I did what capt james suggested and Ive had little luck with that.
What he suggests makes way sense, but, obviously I'm not doing something right
or perhaps I dont have it set up correctly. Ive even tried experimenting with
two very simple files and I couldnt get them to work. Im doing something
fundamentally wrong, I tell ya.

I dont have any hair left on my head.

I could really use some help here, folks - it would be greatly appreciated.
Re: Passing data from one flash file to another BuenasHowdy
4/27/2005 12:00:00 AM
tralfaz -

Thank you. I created two test files with the information you provided and I
got it to work! However, I did have a bit of a problem at first and it took me
a little while to figure it out. Would you beleive that the "s" in
sharedObject needs to be capitalized? That is, it must read "SharedObject".
Before changing this, I was getting "undefined" in the text fields.

Now that I have this info under my belt, its time to apply it to my code. I
hope all goes well (it should).

I really enjoy using Flash and learning to code with ActionScript. Its been
(and continues to be) a fairly large learning curve for me, but Im getting
things done. I have purchased 7 books for use as reference and I have learned
plenty from each. I have also found mucho info online. I must say though,
that I did not come across the info tralfaz provided here. I did however, find
reference to it here at the Macromedia site after the fact. To me, at this
stage, the amount of information that is scattered all over the place is a bit
frustrating. My point is this: can someone recommend a really good reference?

Anyway, thanks again to all who have posted their help and suggestions on this
thread.

Im sure it wont be the last time I ask for help :D
Re: Passing data from one flash file to another BuenasHowdy
4/27/2005 12:00:00 AM
wow! I just checked out Safari - it's a sweet deal, tralfaz! I'm going to subscribe.


Again, thanks for the help and info on Safari.
Re: Passing data from one flash file to another tralfaz
4/27/2005 10:46:16 AM
[quoted text, click to view]

If you really want to unload the first swf you can write anything you
want to save into a shared object that can be read by a loading
swf....
// file1.swf saves data to the shared object
// at the lowest position possible
mso = sharedObject.getLocal("myStuff","/");
mso.data.name = "tralfaz";
mso.data.score = 1727;
mso.flush(); // write to the file

// when needed, load the other swf file.
// button code
on (release) {
loadMovieNum("second.swf", 0); // _level0
}

// file2.swf loads the shared object when it starts up
mso = sharedObject.getLocal("myStuff","/");
text1.text = mso.data.name;
text2.text = mso.data.score;

If you don't really need to unload the first swf when loading the
second one then you won't need all this. Any variable in _level0 can
be read by a movie in another level.

// main movie on _level0
// root timeline variables
someJunk = 100;
someString = "tralfaz";
loadMovieNum("second.swf", 1); // load another movie into level 1

// second.swf can use the vars from _level0
text1.text = _level0.someJunk;
text2.text = _level0.someString;

hope that helps.
tralfaz















Re: Passing data from one flash file to another tralfaz
4/27/2005 7:42:56 PM
[quoted text, click to view]

Sorry about that. I use Flash MX, not MX2004. They changed Flash to
be case sensitive with MX2004. MM had established a traditional
format to use a lowercase letter on the first word with uppercase
letter starting the 2nd word. I don't know why they changed some
function names to use uppercase first letter like that.

[quoted text, click to view]

I am really annoyed by the lack or real-world examples in Flash help.
Either there is no usage example at all or the example is of some
peculiar usage of the command. I wrote the various localConnection
examples on my website as each requirement came up, having to figure
out the best way to do it each time.

For a good reference I subscribe to an online technical book service
called Safari. http://safari.oreilly.com/ For $10 per month you can
read any 5 technical books they have during that month. Lots of Flash
books and PHP, Photoshop etc. After 30 days you can change the books
to new ones. You can also search through thousands of books for code
snippets. For me it's better than buying books.

regards,
tralfaz

AddThis Social Bookmark Button