I’d like to create a map with an array… I saw a lot of tutorials about platform game creatio on flash, but no one with the map moving.
So, I try to do it by myself.
Before moving my map, I’ve to create it, and THAT’s my problem !
So, I let you have a see on three layers code and make your opinion on.
Flash announce me an error #1009, he can’t access to a property or method of null object reference and I don’t see once ?
at Sansnom_fla::MainTimeline/createMap()
at Sansnom_fla::MainTimeline/frame1()
Layer 1
var grid:MovieClip = new MovieClip();
// liste d'affichage
addChild(grid)
createMap()
Layer 2
function createMap():void{
for (var i:int=0; i<20; i++){
for (var j:int=0; j<15; j++){
var T:int = 32
var dT:int = T*.5
var f:int = map[j][i]
if(f>0) {
var t:block = new block()
t.x= i*T;
t.y= j*T;
t.gotoAndStop(f)
grid.addChild(t)
}
}
}
}
Layer 3
var map:Array = [
[1,1,1,1,1,1,10,0,0,11,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,0,1],
[1,0,0,0,0,0,6,1,0,0,4,4,4,4,0,0,6,1,0,1],
[1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,1,6,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,6,0,0,1,0,0,1,0,0,1,0,0,1,2,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,3,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
]
var stock:Array = [
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
]
Thanks a lot !
Ps : As you could learn, block is a movieClip where once frame is a particular block.
Why are you splitting code between layers? Don’t do that. Also you are calling
mapin layer 2 before it even exists yet (it isn’t created until layer 3’s code is run) so my recommendation is to stick it all into 1 layer, on 1 frame.Then adjust your code order like so:
Also don’t forget the
;character, you have a habit of missing them out. Anyway, hope this helps!