1

I wan to pass the variable of shower_cost from the first scene to the second scene. The variable will be displayed in a dynamic text. when the show button is hit on the second scene, the show_cost will appear.

The problem here is seems there is something wrong while retrieving the sharedobjects because it does not show the cost when show button is hit.

First scene actionscript

import flash.events.MouseEvent;
import flash.net.SharedObject;

shower_ok_btn.addEventListener(MouseEvent.CLICK, shower_multiplyClick);
shower_back_btn.addEventListener(MouseEvent.CLICK, shower_backClick);

var shower_multiSym:Boolean = false;
var shower_backSym:Boolean = false;

shower_usage.restrict="0-9";
shower_power.restrict="0-9";
shower_power.border=true;
shower_usage.border=true;

var shower_input1:String;
var shower_input2:String;
var shower_multiResult:Number;
var shower_costResult:Number;
var show_shower=SharedObject.getLocal("shower");

function shower_multiplyClick(event:MouseEvent):void{
    shower_multiSym=true;
    shower_backSym=false;


    show_shower.data.showcost =shower_cost.text;
    show_shower.data.showpower=shower_total_power.text;

    shower_text_total_power.text="total power(kwh):";
    shower_text_cost.text="Cost (rm):";

    shower_total_power.border=true;
    shower_cost.border=true;

    shower_input1=shower_usage.text;
    shower_input2=shower_power.text;

    if(shower_multiSym==true){
        shower_multiResult=parseInt(shower_input1)*parseInt(shower_input2)/1000;
        shower_multiResult.toString();
        shower_total_power.text = String(shower_multiResult);
    }
    else{
        shower_total_power.text="Please Choose an option";
    }

    shower_costResult=.218*(parseInt(shower_input1)* parseInt(shower_input2))/1000;
    shower_costResult.toString();
    shower_cost.text=String(shower_costResult);
    trace(shower_costResult);

}

function shower_backClick(event:MouseEvent):void{
    shower_multiSym=false;
    shower_backSym=true;
    gotoAndStop(1,"Scene 2");
}

stop();

The second scene actionscript:

import flash.net.SharedObject;

show_btn.addEventListener(MouseEvent.CLICK,showReport);

var state=0;
function showReport(e:MouseEvent):void{

    var state=1;

    if(state==1){

    Report_cost_shower.border=true;
    var show_shower2=SharedObject.getLocal("shower");
    Report_cost_shower.text=show_shower2.data.showcost;

}
}
stop();
whoami
  • 173
  • 3
  • 15

1 Answers1

0

I wouldn't recommend using SharedObject to pass data between objects, it's slow and unreliable. I've been using a Global class for this - see https://github.com/inruntime/AS3-Global-Object

You can use it this way -

import com.inruntime.utils.*;

    // initialize the global object
    // you have to repeat this step in every class that will use the global
    private var $:Global = Global.getInstance();

    $.show_shower = shower_cost.text;
xims
  • 1,570
  • 17
  • 22