|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
variables across levels?
I've got into a twist over levels and roots and I'm hoping someone can help. I've loaded some variables into the root from a button within a movie clip on the stage.
I think it goes _root/movieclip/button which I believe is 2 levels? I've loaded variables into _root but I want to look at them on frame 1 of the movieclip as well. How do I do that? The name of the variable I want to look at is 'picture' so I thought that to reference that variable I go: _root.picture but that doesn't seem to work. I've checked that the variable exists at level 0 and it does. What am I doing wrong? (full script below from the button itself) Code:
on (press) {
loadVariablesNum("query.php?id=12", 0);
_root.createTextField("theTextBox", 20, 385, 100, 350, 520);
_root.theTextBox.background = true;
_root.theTextBox.border = true;
_root.theTextBox.backgroundColor = 0xFFFFFF;
//white
_root.theTextBox.borderColor = 0x666666;
//black
_root.theTextBox.multiline = true;
_root.theTextBox.wordWrap = true;
_root.theTextBox.html = true;
_root.theTextBox.variable = "storyField";
//create some formatting for our text box
_root.myTextFormat = new TextFormat();
_root.myTextFormat.font = "Arial";
_root.myTextFormat.size = 12;
_root.myTextFormat.color = 0x000000;
//black
//format our text box
_root.theTextBox.setNewTextFormat(myTextFormat);
//create image holders
_root.createEmptyMovieClip("imageHolder1", 200);
_root.createEmptyMovieClip("imageHolder2", 201);
_root.imageHolder1._x = 100;
_root.imageHolder1._y = 100;
_root.imageHolder2._x = 100;
_root.imageHolder2._y = 350;
//load the content from database
_root.imageHolder1.loadMovie(_root.picture);
_root.imageHolder2.loadMovie(_root.picture);
}
|
|
#2
|
|||
|
|||
|
Hi, just a thought but try moving loadVariablesNum("query.php?id=12", 0); to the root first frame. This could be a problem with the data not being fully read by the time you use loadmovie. If it works after this then you know you need to make a check to ensure all the data is read prior to trying to load the pictures.
|
|
#3
|
|||
|
|||
|
Thanks, I'll try that but it won't solve my problem ultimately because the loadvariables has to happen on the button because I'm making a different query on the database/loading a different set of variables for each individual button press.
If I do a trace of the variables then I find that they are all currently undefined within the movieclip that contains the button. |
|
#4
|
|||
|
|||
|
Hi, I only suggested the above as a testing practise. Someone else had similar problems and found the solution to be that the data hadnt loaded fully prior to trying to use it. The results were the same as yours currently are.
Try something like this: make a new movie in root. give it the instance name dbaccess. make it two keyframes long. in the first kf have: function readTheData(idNumber) { _root.completed = false; loadVariablesNum("query.php?id="+idNumber, 0); } if(_root.completed) { //load the content from database _root.imageHolder1.loadMovie(_root.picture); _root.imageHolder2.loadMovie(_root.picture); stop(); } in the second kf have: gotoAndPlay(1); Now remove the loadvars and image loading bit from your buttons. and use: _root.dbaccess.readTheData(12); I'm not sure how your database data is fed back. if you use arrays or objects simply add a new variable called completed and set it to true. I wrote all that in here and not in flash so I havent tested it but I'm pretty sure that will work fine. If you need to use different values or more than one var for different buttons simply add more functions to the dbaccess movie or expand the current one. i.e. function readTheNews(topicNumber, topicCount, topicContent) { _root.completed = false; loadVariablesNum("query.php?id="+idNumber+"&count="+topicCount+"&content="topicContent, 0); } I think you can work it all out from here. You can even specify a target clip (i think) to load into. I really hope this helps cos I know db's can be a pain! |
|
#5
|
|||
|
|||
|
This works great - the first time you click the button! If you click another button (different id number) or reclick that button the text reloads in the text box but the images don't reload - they dissappear.
Puzzling! |
|
#6
|
|||
|
|||
|
|
|
#7
|
|||
|
|||
|
That's useful. I still seem to have the same problem though despite adding in -
Code:
delete _root.imageHolder1;
delete _root.imageHolder2;
_root.unloadMovieNum("imageHolder1");
_root.unloadMovieNum("imageHolder2");
_root.createEmptyMovieClip("imageHolder1", 200);
_root.createEmptyMovieClip("imageHolder2", 201);
Another question - whats the difference between these three lines of code? Code:
loadVariablesNum("http://192.168.0.1/playout/query.php?id="+idNumber, _level0);
loadVariablesNum("http://192.168.0.1/playout/query.php?id="+idNumber, 0);
loadVariablesNum("http://192.168.0.1/playout/query.php?id="+idNumber, _root);
Last edited by Matt Phelps : December 6th, 2003 at 10:42 AM. |
|
#8
|
|||
|
|||
|
Hi, I dont use delete that often. If I want to get rid of a movie clip I usually use:
_root.imageHolder1.unloadMovie(); _root.imageHolder2.unloadMovie(); Try removing the delete statements and swapping the relevant lines with the above. As for part 2 of your question, this link has more information. |
|
#9
|
|||
|
|||
|
does unloadmovie delete the contents of the clip or remove the whole movie from the stage? I think it's the later...right?
|
|
#10
|
|||
|
|||
|
bingo
|
![]() |
| Viewing: Dev Shed Forums > Web Design > Flash Help > variables across levels? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|