Skip to main content
Inspiring
January 27, 2017
Question

How I can load to data on another scene.

  • January 27, 2017
  • 2 replies
  • 1562 views

I'm trying to get data on scene 1 from to scene 2.

I was write a Shared Object scene1

///inputs

var dejavuscor = SharedObject.getLocal("addve");

if(dejavuscor.data.dejavuscor1 == null){ //if it is being called for the first time it will be null. so change it to 0.

                dejavuscor.data.dejavuscor1 = 0;

            }

          

          

hscore.text = dejavuscor.data.dejavuscor1;

////saving

butonred.addEventListener(MouseEvent.CLICK, redButton42);

function redButton42(event:MouseEvent):void

{

      

        ScoreHolder.score += 10;

        sco_1.text = ScoreHolder.score.toString();

        if(ScoreHolder.score > dejavuscor.data.dejavuscor1){

                    //if score greater than highscore then set highscore = score and save it.

                    dejavuscor.data.dejavuscor1 = ScoreHolder.score;

                    dejavuscor.flush();

                }

}

//////////

Now I write a script for use the same data on another scene.

SCRİPT

/////

package  {

    import flash.net.SharedObject;

    public class Dost {

  

    public static var dejavuscor2 = SharedObject.getLocal("addve");

        public function Dost() {

            // constructor code

        }

    }

  

}

/////Frame on scene 2

import Dost;

import flash.net.SharedObject;

scoreprevious.text = Dost.dejavuscor2;

But nothing happen.I seen [object SharedObject] on the screen when I test scene 2..How can I do that.

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
January 27, 2017

while Ned Murphy​ 's advice is understated when using actionscript 2, with actionscript 3 there were no problems. but it's still easier to understand what you're doing when you avoid scenes with as3.

anyway, variables retain their values across scenes so there's no reason a sharedobject is necessary, but if you have other reasons for using it, no problem.  you just can't use 'test scenes' and fail to execute code in scene 1 and expect have scene 2 respond as if you executed the code in scene 2.

ie, use test movie, not test scene.

KucuKekoAuthor
Inspiring
January 27, 2017

Yes I tried that but I got nothing again.Here is what I tried so far

I put the scene 2 to top on the scene list and test movie - same result

I put the scene 1 to top on the scene list and made a button for go to scene 2 and test movie - same result

I'm not using the script "dost" at scene 1 is this may the reason ? I made a mistake somewhere but I can't see.

kglad
Community Expert
Community Expert
January 27, 2017

Microsoft OneDrive - Access files anywhere. Create docs with free Office Online.


do you see any compiler errors when you test?

i see a few and once those are eliminated, trace works (which is expected).

Ned Murphy
Legend
January 27, 2017

You are better off to avoid using scenes at all.  They have been problematic since the day they came into being.  Use frames of the main timeline or movieclips instead