Reading from text file.

  • RockmanTV
  • Proficient
  • Proficient
  • RockmanTV
  • Posts: 348

Post 3+ Months Ago

Ok, so this time what I'm trying to do is read in from a txt files and store that value in a variable. THe value of that variable will determine which scene flash sends me too. Here's my code.

Code: [ Select ]
loadVariablesNum ("bookmark.txt", 0);
if (Bookmark==Scene1){
    gotoAndPlay("Scene2", 1)
} else if (Bookmark==Scene2){
    gotoAndPlay("Scene3", 1)
  1. loadVariablesNum ("bookmark.txt", 0);
  2. gotoAndPlay(1);
  3. if (Bookmark==Scene1){
  4.     gotoAndPlay("Scene2", 1)
  5. } else if (Bookmark==Scene2){
  6.     gotoAndPlay("Scene3", 1)
  7. }

I've chmodded my txt file correctly and I've been able to print out whats inside the Bookmark variable in a dynamic text field, but I have not been able to get this work. Any ideas? The other two scenes consist of one frame, some text and a stop() function in their actions panel.
  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

loadVariablesNum isn't an instant action, you have to wait for the information to be fully loaded before you can access the variables within.

The LoadVars() object was created to make doing this easier.

Also, your if statements are wrong... Scene1 should be in quotes otherwise Flash thinks it is a variable. And also, it's kind of redundant to check if it equals something then gotoAndPlay what it equals...

So try something like this...

Code: [ Select ]
myLV = new LoadVars();
myLV.onLoad = function(success) {
    if (success) {
        gotoAndPlay(Bookmark, 1);
  1. myLV = new LoadVars();
  2. myLV.onLoad = function(success) {
  3.     if (success) {
  4.         gotoAndPlay(Bookmark, 1);
  5.     }
  6. };
  7. myLV.load("bookmark.txt");

Untested, but that's the basic gist.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 9 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum

© 1998-2017. Ozzu® is a registered trademark of Unmelted, LLC.