|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I recently worked how to access variables on different levels and have decided to keep the variables that I need constant access to in other levels within Level0 of the Flash file. Here what I want to achieve:
I've created a login screen that uses both PHP and MySQL. I can get the Flash to use the PHP to query the MySQL database in order to match the users email and then the password in order to log them in. In return I send the member ID back to a dynamic textbox within Level0 with the variable referred to as "memberID". Now the relevant member ID is on display and I assumed that the value of the "memberID" variable is now available to any other level. Now what I want to do from now is be able to access this variable by stating memberID = _level0.memberID, so that this will later become $memberID when it is accessed by another PHP script on a given level other then the root. However when I come to access this, there doesn't seem to be anything there, so another PHP script I use later will not work properly because there won't be a member ID to use. I know that the PHP file is working correctly as if I manually set the value of the "memberID" variable within Level0 in Flash, it will pass the variable required to the PHP script, so my question is: Is there a problem with variable persistence, i.e. is there a difference in manually assigning a value to the variable in Flash, to one that is assigned a value later by a PHP script? I believe there must be difference and that the value of the memberID returned from the PHP script will only exist in one instance, but disappears the moment I move around the timeline. My basic design for the Flash application will revolve around having certain variables to be available within Level0 of the flash file and the value of those variables will be assigned by one PHP script, which I will then want to make that value accessible in other PHP scripts later (hence the member ID thing). Is it possible to temporary store those values on Level0 and keep them iun existence for as long as I need them? Or have I got it all wrong and that after returning a value to variable in Flash from a PHP script, it only exists for one instance and will have already disappeared them moment I try to use another PHP script to access that same variable with Level0 of the Flash file? The only other alternative I can think of is to use Cookies to store the member ID, but I would rather keep everything in Flash if it is possible. Just in case this may be of some significance, I'm currently developing this on Flash 5. Thanks any help you can give me. Last edited by Todd Terry : February 24th, 2003 at 04:32 AM. |
|
#2
|
|||
|
|||
|
Can you post some code??
|
|
#3
|
|||
|
|||
|
As I said in my previous post, there doesn't appear to be anything wrong with the PHP script. I'm assuming that it is operating correctly as when I manually input a value in the variable memberID at _level0 and then publish the flash file, the PHP script is able to read in the value, where another SWF on Level7 of the base Flash file is able to copy the value by doing memberID = _level0.memberID; just before I invoke the PHP script. The PHP script is then able to read it in and assign the value to $memberID within the PHP script.
I also know that for the login PHP script, I can send the value of $memberID back to the memberID variable on _level0 as it is displayed during my testing phase of the application, so I know the value of $memberID from the PHP script is being sent back to the Flash file. What I don't understand is that when I want to use that value that is now being displayed on the Flash file within that dynamic textbox in another PHP script later in the timeline, it appears that the value no longer exists, even though it was just assigned by the previous PHP script. Does anyone know if there is a persistency issue? If you would still like to see the code, which part do you need to see? |
|
#4
|
|||
|
|||
|
i'm sensing that the problem is that you are assigning the text box variable your memberID value, and not an actual variable. try setting a regular variable eqaul to the memberID:
_level0.memberID = memberID; or something like that... |
|
#5
|
|||
|
|||
|
Let me just clear a few things up.
There is a variable that sits on Level0 of the base Flash file called memberID (later referred to as _level0.memberID). It is blank to begin with. A login PHP script will then authenticate the user's information and then return their member ID value from the database and sends in back to _level0.memberID. Later on in the application on Level7 (the contents level), another script will fire off (my page tracking script) and this will need member ID in order to track the relevant user, so now the ID is required. I make a copy of the value that should now be sitting in _level0.memberID by invoking memberID = _level0.memberID; so now the variable is ready for the page tracking PHP script and that becomes $memberID for PHP. If we take your example of _level0.memberID = memberID; then it will be blank because by that logic _level0.memberID will now store the contents of memberID which is also blank at this time. What I need is for the contents of _level0.memberID to be copied to variable memberID on Level7. Unfortunately, I get the feeling that Flash is not able to hold the value for very long and disappears the moment it was first brought in. Any suggestions? One last thing. What is the difference between "_level0.memberID" and "_level0:memberID"? |
|
#6
|
|||
|
|||
|
hey,
whatever method you used to load the variables into flash determines where your returned variables lie. if, in your php script, you had something like: print "_level0.memberID=$memberID"; then that would set the _level0.memberID variable in flash to the value of $memberID. Once this variable is set, if you load anything else into the _level0 (or _root) timeline, all variables, movieclips and graphics will be completely replaced by whatever you loaded in. This is only the case if you load a movie into that level like: _level0.loadMovie("myexternal.swf"); or _root.loadMovie("myexternal.swf"); If, when you load your variables, you use loadVariablesNum, then the variables will reside on whatever level you specififed to load the variables into; unless you printed the top statement like i had before. printing _levelx.variable=value will explicitly set that variable on whatever your x value is. Flash will keep whatever variables you create/load for however long the encapulating object exists (or you manually delete them using the delete method). This variable handling is no different for _levels, as _levels are just timelines, which are just special MovieClips in the first place. That means that if you set your variable using your php script, and want to set a _level7 variable equal to that, you can just assign a _level7.memberID = to your _level0.memberID: _level7.memberID = _level0.memberID; this is assuming that you assigned the variable to _level0 in the first place (use traces to tell you this). You might want to look into using the LoadVars Object, which will let you speicify what variables to send, and where to put the recieved variables when they return. It's probably a little easier than using levels, since all you need to keep track of is the object that you loaded your variables into. cheers, bret |
|
#7
|
|||||||
|
|||||||
|
Thanks for the suggestions so far Bret. Let me see if I've got this logic figured out correctly.
Quote:
This is what I have done once the PHP script acknowledges that the user details are correct. It does return the correct value to a dynamic textbox referred to as _level0.memberID. Quote:
I don't believe I've loaded anything else into the _level0 of the file. As I said, the main interface resides on _level8 and the main contents of the Flash file resides in _level7 (this is where the login screens, register screens etc come in). Is that the problem. The fact that I'm loading other SWF at different levels? Quote:
This is the main issue I have. I can clearly see that a value was returned by the login PHP script as the value of the member ID is displayed in the dynamic textbox referred to as _level0.memberID. So why can't I now assign that value to another variable at a different level so that a PHP script that runs at a particular level other then the root can now use that variable. I only ask about this as I'm not too sure how you would submit the value of the variable _level0.memberID to a PHP script that is invoked by a SWF at _level7. Quote:
The page tracking PHP script is invoked automatically as the head piece moves across it on the time line. It is at this point that I set up the relevant variables before the PHP script is called. In my current code, I have essentially done what you have stated, except at the time I didn't explicitly state _level7.memberID. Perhaps this is the problem? Quote:
This is not an option right now. I'm working in Flash 5, although at some point, I might transfer this to Flash MX. However this is something I rather not do at the moment. Anyway thanks again for your suggestions and any others would be most welcome. |
|
#8
|
|||
|
|||
|
okay, here's a .zip with three files.. an external .txt file, and two .flas. Create .swfs of both and then run "loadLevel.fla". you'll see three things trace:
level7.memberID = 21312412312 variables loaded correctly : _level0.memberID= 21312412312 Error opening URL "file:///C|/wherever your file is" take a look at both of the .fla's to see that once the variable is loaded in, it unloads the movieclip checking for loading (that's where the error comes from. it tries to load nothing in, and obviously can't find it. it doesn't actually affect anything). the clip traces _level0.memberID the movie "myLevel7.fla" sets memberID = _level0.memberID and then traces "level7.memberID = "+_level7.memberID if you run the myLevel7 on it's own, it won't trace any value, because it's not level 7 until we load it into the main movie... hopefully you can use some of this logic in your variable manipulation. write back if you have questions about my code/methods (saved in flash 5 too..let me know if that doesn't work) cheers, bret |
|
#9
|
|||
|
|||
|
and just so you know.. everything that you explained (back to me) was correct
![]() |
|
#10
|
|||
|
|||
|
Thanks Bret. I'll be sure to take alook at those as soon as I return home.
Just a quick recap to make sure I've got it: A variable in the base SWF has a variable called _level0.memberID and is blank initially. Later a SWF file sitting on _level7 will invoke a login PHP script. Upon successful completion, it will return the value from PHP to the variable _level0.memberID (this will be the member ID from the MySQL database). Later on in the timeline on _level7, another script will automatically go off for the page tracking and will initally set up the variables for the current screen it is on as well as bringing in the current member ID from _level0.memberID by way of: _level7.memberID = level0.memberID; This should copy the value sent earlier from the login PHP script to the _level7.memberID variable. Then the page tracking PHP is invoked and the script will now have a value to use in $memberID. One question though. Will the fact that assigning _level7.memberID to the PHP file have any effect since I want that value to be $memberID in PHP? |
|
#11
|
|||
|
|||
|
one thing about your last post. If you are in the timeline of level7, then you only need to say :
this.memberID = _level0.memberID; because `this' is now on level7, it will set the _level7.memberID equal to your level0 variable. A good way to see where these variables end up is be using the Debugger and clicking on the variables Tab once the movie is up and running. This will show you the path and the values of all exisiting variables. As for your second question, it won't affect it at all. If you use : $memberID = _POST['memberID']; or something like that then obviosly when you send the info back to the php script, there won't be any conflicts... hope that helps. cheers, bret |
|
#12
|
|||
|
|||
|
Yes, I think I understand now. Thanks again.
|
|
#13
|
|||
|
|||
|
Okay, I've checked out your example and I think I'm starting to get it. just a few issues to clear up.
The text file you had defines the variable memberID along with the value. Am I correct in assuming that variable is then created at _level0 and then assigned the value, once the loadLevel.SWF calls for the text file? The reason I ask is that I have already created a dynamic textbox with the variable name _level0.memberID, but initially it's blank. It only gets filled in later. Once it does, may I assume the the variable will stay there as long as I don't overwrite it? The value for the variable from the text file is copied and not just referenced. I'm still trying to work out why the value of the ID that I send to the _level0.memberID disappears after I send it the value from PHP. |
|
#14
|
|||
|
|||
|
you're right, the value is copied not just referenced. i think there might be a problem in the naming the text field variable the same thing.. try just naming it something else and assigning it the value...
but the way the variable is created is as follows. the text file holds the variable and the value. it doesn't exist in _level0 until you use the loadVariablesNum method to load the text file in. because you loaded the variables into the _level, all variables that existed in the text file will now exist in your target path (in our case, _level0). you could have loaded the variables into a movieclip, and in that case, memberID would have been created inside of that movieclip... so, for this reason, i would rename your text box, and then just assign the value of the text box to your memberID once it's loaded in... that might cause some unexpected problems (meaning i'm not sure what will happen :P) cheers, bret |
|
#15
|
|||
|
|||
|
Thanks again. I'm getting to a point where I'm getting tired of trying to work out why the variable assigned from a PHP script won't stick within the Flash file. I think I'm going to have to resort to using sessions on PHP.
|
![]() |
|