Skip to main content
Inspiring
September 4, 2013
Answered

parse & decode with SkinValue variable

  • September 4, 2013
  • 1 reply
  • 3381 views

I've got a problem. I'm making a game and I want my player to change skin when he's entering in the map "monde".

I've got 2 versions of fla files. One for a PC version, and one for android version.

In my “PC version” the code with skinValue is working and it’s not in my “Air for Android version”.

In my PC version I’ve got a player class named player.as :

public function Player(stageRef:Stage, walkRate:Number, targetBuffer:Number){

gotoAndStop(“default”+skinValue);

….

public function startWalking;

gotoAndStop(“walk”+skinValue);

....

public function stopWalking(e:Event):void{

removeEventListener(Event.ENTER_FRAME, walk);

gotoAndStop("default"+skinValue);

In my Engine class (where the game is controled) Engine.as :

var isMap:Boolean = thisBack == “monde”;

    if (isMap) {

    player.skinValue = “car”;

    }

    else {

    player.skinValue = “”;

    }

    }

My player'got extra frames for that named "walkcar" and "defaultcar". and it’s WORKING GREAT !

But in my AIR version I’ve got this error :

Error #2109: Frame label defaultnull not found in scene defaultnull.

at flash.display::MovieClip/gotoAndStop()

at com.laserdragonuniversity.alpaca::Player()

at com.laserdragonuniversity.alpaca::Engine/createBackground()

at com.laserdragonuniversity.alpaca::Engine/configLoaded()

at flash.events::EventDispatcher/dispatchEventFunction()

at flash.events::EventDispatcher/dispatchEvent()

at flash.net::URLLoader/onComplete()

I search what could be the problem and it seems that JSON is causing this error.

In my PC version I've got, in my engine.as file :

private function linesLoaded(e:Event):void{

            linesData = JSON.decode(speechLoader.data);

...

private function configLoaded(e:Event):void{

            configData = JSON.decode(configLoader.data);

I have to change "decode" by "parse" for my android version and it seems that it's the problem for my Skinvalue ! When it's "parse"..it won't work !

Any idea why ?

Thx !

This topic has been closed for replies.
Correct answer Stephdidou

skinValue needs to be defined in the class that contains Player() and needs to be defined in the class that contains startWalking() before each executes.

but i'm pretty sure you won't understand how to fix that.  i think you will need someone to download and fix your files for you.


Found the solution ! It was simply an initialization problem. I've just had to add  = "" at the end of "public var skinValue:String."

So it wasn't at all a define problem. Just an initialization problem...

Thanks anyway,

1 reply

kglad
Community Expert
Community Expert
September 4, 2013

skinValue is being assigned a value of null when that gotoAndStop executes.

use the trace function to debug.

p.s. the following is from:http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=gladstien

At the time of this writing, the Adobe Facebook ActionScript (version 1.8.1) code uses Mike Chamber's JSON class.  But if you are publishing for Flash Player 11 or better, you must use the native Flash JSON class.

Both JSON classes are similar in that they are named the same and use static functions to convert to and from JSON format. Where Chamber's JSON class uses JSON.decode() and JSON.encode(), the native Flash JSON class uses JSON.parse() and JSON.stringify().

Inspiring
September 4, 2013

trace(skinValue) isn't showing anything....

kglad
Community Expert
Community Expert
September 4, 2013

that's no surprise.

you need to debug your code.  to start, it's not clear from what you posted whether the skinValue in stopWalking() is using the same variable as the one assigned in Engine and it's not clear whether a value is assigned in Engine before you try and use it in Player.