Copy link to clipboard
Copied
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 !
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,
Copy link to clipboard
Copied
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().
Copy link to clipboard
Copied
trace(skinValue) isn't showing anything....
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I'll look into it but it's really weird, if I change JSON.parse by JSON.decode, everything's working ! So I don't understand how my skinValue could be the problem...
Copy link to clipboard
Copied
The basic way the engine makes the character animate is to use frame names for specific character states. So when the code wants the character to look like it's walking it goes to the frame named "walk". I've made sure that I have a "walk" frame on the character (or the game won't work).I've add a whole new frame for each of these states that is the name of the state plus the skin name, then I can create a set of animations that represent the new skin:
Using "walk" as an example:
Basic frame name: "walk"
Car skin frame name: "walkcar"
(I've made a "car" version for each player frame)
In Player.as I'll add a String variable called "skinValue":
public var skinValue:String;
And then in code I've changed the code from:
gotoAndStop("walk")
to:
gotoAndStop("walk"+skinValue)
So then if I set the "skinValue" to "car", the code "walk"+skinValue would evaluate to "walkcar" and it would go to the car frame. I've set the value of skinValue to "" (the empty string) to get it to go back to the regular animation.
I've set the value of skinValue outside of this function. Since I want this to happen when I switch to the map, then the best place to do this is when the game switches between the map and some other screen.
In Engine.as I've got the function "createBackground(thisBack:String)". This gets called whenever the background changes. So when the game switches to the map, the function will get called essentially like createBackground("map")
So I've put this code :
var isMap:Boolean = thisBack == "monde"; //this should be the name of your map screen
if (isMap) {
player.skinValue = "car";
}
else {
player.skinValue = "";
}
This should make it so when the map appears, the skinValue is set to the car skin and otherwise it's set to the blank skin.
So what could be possible wrong with all that ?
Copy link to clipboard
Copied
abstracting your code and posting what you think it does is not usually helpful because you wouldn't be here if your code did what you think it does.
again, start to debug by using the trace function to determine what executes first, using skinValue or assigning skin value. then use the trace function to see if player in Engine is the same instance as player in Player.
Copy link to clipboard
Copied
Here's what the trace function tells me :
Creating new background: wind
null
defaultnull
ArgumentError: Error #2109: Frame label defaultnull not found in scene defaultnull.
Do you have an idea what could be the problem ?
Copy link to clipboard
Copied
yes, skinValue is not defined.
Copy link to clipboard
Copied
So maybe I'm placing this code in the wrong place... ? Do you think that could be the problem ?
var isMap:Boolean = thisBack == “monde”;
if (isMap) { player.skinValue = “car”;
} else { player.skinValue = “”;
}
Copy link to clipboard
Copied
yes, that code be the problem.
ie,that code could execute AFTER you try and use skinValue.
or that code could be out of scope.
Copy link to clipboard
Copied
Yeah, I think I need to call it at the begining of my code (when the background is created), but weirdly if I put the code a the begining I've got this error :
C:\Users\Stéphan\Desktop\05 septembre\le jeu_menu ok\La Brousse en folie\com\laserdragonuniversity\alpaca\Engine.as, ligne 76 | 1120: Accès à la propriété non définie isMap. |
C:\Users\Stéphan\Desktop\05 septembre\le jeu_menu ok\La Brousse en folie\com\laserdragonuniversity\alpaca\Engine.as, ligne 75 | 1120: Accès à la propriété non définie thisBack. |
C:\Users\Stéphan\Desktop\05 septembre\le jeu_menu ok\La Brousse en folie\com\laserdragonuniversity\alpaca\Engine.as, ligne 75 | 1120: Accès à la propriété non définie thisBack. |
But if I put in the middle of Engine.as, I don't have this error (but I've got the error that skinValue is not defined...)...
Copy link to clipboard
Copied
if you have less than 50 lines of code, you could post all your code. otherwise, someone will probably need to download your files to help you.
Copy link to clipboard
Copied
private function createBackground(thisBack:String):void{
trace("Creating new background: "+thisBack);
var playerLoc:MovieClip;
back = new Background(stage, thisBack);
addChild(back);
obstacles = back.returnObstacles();
for (var i in obstacles){
addChild(obstacles);
}
if (restoring){
playerLoc = new MovieClip();
playerLoc.x = 0;
playerLoc.y = 0;
} else if (lastLocation){
var lastLocName = "startPoint_"+lastLocation;
playerLoc = back.currentBack[lastLocName];
} else {
playerLoc = back.currentBack.startPoint;
}
if(toolbar) playerScale = puzzle.setPlayerScale(thisBack);
player = new Player(stage, walkRate, targetBuffer);
if (playerLoc.x > stage.stageWidth / 2){
player.scaleX = -playerScale;
}else {
player.scaleX = playerScale;
}
player.scaleY = playerScale;
player.x = playerLoc.x;
player.y = playerLoc.y;
if (restoring){
saver.dispatchEvent(new Event("repose"));
restoring = false;
}
addChild(player);
player.addEventListener("playerWalking", startDepth, false, 0, true);
player.name = playerName;
foreground = back.returnForeground();
for (i in foreground){
addChild(foreground);
}
usableItems = back.returnItems();
exits = back.returnExits();
for (i in exits){
addChild(exits);
}
// Add event listeners for all the usable items
for (i in usableItems){
var thisClip = usableItems;
thisClip.buttonMode = true;
thisClip.addEventListener(MouseEvent.CLICK, examine, false, 0, true);
thisClip.gotoAndStop(1);
}
back.currentBack.ground.addEventListener(MouseEvent.CLICK, movePlayer, false, 0, true);
// Keep the toolbar at the highest depth
if (toolbar){
puzzle.newBackground(thisBack);
changeUIDepth();
toolbar.addListeners();
// Remove any items the player has already picked up
var allInv:Array = inv.returnItems("all");
for (i in usableItems){
for (var j in allInv){
if (usableItems.displayName == allInv
.displayName){ usableItems.visible = false;
}
}
}
}
}
So, if I'm placing the code for the skinValue before "createBackground" function it says that "isMap" and "thisBack" are not defined, and if I'm placing it just before the last "}" of the end, it says defaultnull..
Thank you veru much for your help (again) !
Copy link to clipboard
Copied
re: the class that contains createBackground():
are you trying to define skinValue in that class?
are you trying to use skinValue in that class?
Copy link to clipboard
Copied
Yes, i'm tying to define the skinvalue in that class (var ismap...in order to tell him to change the skin only in the map "monde").I've got a Player class (for the player only) and in that class I put gotoandstop (default+skinvalue)
Copy link to clipboard
Copied
where's isMap defined?
Copy link to clipboard
Copied
Oh...I didn't think it was necessary to define isMap as it was working before like this (maybe I was lucky). Ok so I need to define isMap.. but how could I define it..? because I already code that isMap = thisback ==monde
and back is already define in the begining of the code no ?
private function createBackground(thisBack:String):void{
...
back = new Background(stage, thisBack);
addChild(back);
...
Copy link to clipboard
Copied
publish that createBackground() method with the lines of code that cause an error.
Copy link to clipboard
Copied
Ok..so what do I have to do ?....change all the codes...?????
Copy link to clipboard
Copied
copy and paste the code you used that showed an error message, show the error message and indicate the problematic line of code.
Copy link to clipboard
Copied
public function Player(stageRef:Stage, walkRate:Number, targetBuffer:Number){
gotoAndStop(“default”+skinValue);
public function startWalking;
gotoAndStop(“walk”+skinValue);
Wherever I put "+skinValue" 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()
so the problematic line of could would be
gotoAndStop(“something”+skinValue);
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Thanks, I'll try before giving you my files. I can't pay for all my problems (already sent you my files two weeks ago for dragging item on an android device).
Copy link to clipboard
Copied
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,
Find more inspiration, events, and resources on the new Adobe Community
Explore Now