The game I’m working on is a racing game where the track is generated randomly. But I’m having a problem, here’s the code I’m working on:
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**function**[/COLOR] TrackContainer[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]:[COLOR=#0000FF]void[/COLOR][COLOR=#000000]{[/COLOR]
trackDb=[COLOR=#000000][[/COLOR]
[COLOR=#000000]{[/COLOR]getObject:[COLOR=#000000]**function**[/COLOR] newTrackSquare[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR][COLOR=#0000FF]return[/COLOR] [COLOR=#000000]**new**[/COLOR] TrackSquare[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];[COLOR=#000000]}[/COLOR], currX:[COLOR=#000080]0[/COLOR], currY:-[COLOR=#000080]50[/COLOR][COLOR=#000000]}[/COLOR],
[COLOR=#000000]{[/COLOR]getObject:[COLOR=#000000]**function**[/COLOR] newTrackLeftTurn[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR][COLOR=#0000FF]return[/COLOR] [COLOR=#000000]**new**[/COLOR] TrackLeftTurn[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];[COLOR=#000000]}[/COLOR], currX:-[COLOR=#000080]50[/COLOR], currY:-[COLOR=#000080]50[/COLOR][COLOR=#000000]}[/COLOR],
[COLOR=#000000]{[/COLOR]getObject:[COLOR=#000000]**function**[/COLOR] newTrackRightTurn[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR][COLOR=#0000FF]return[/COLOR] [COLOR=#000000]**new**[/COLOR] TrackRightTurn[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR];[COLOR=#000000]}[/COLOR], currX:[COLOR=#000080]50[/COLOR], currY:-[COLOR=#000080]50[/COLOR][COLOR=#000000]}[/COLOR]
[COLOR=#000000]][/COLOR];
[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]
Basically, the idea is to create an array to hold all the track information. The important part of this array is the getObject function, which will help me build the track in this code-
ActionScript Code:
[FONT=Courier New][LEFT][COLOR=#0000FF]public[/COLOR] [COLOR=#000000]**function**[/COLOR] updateTrack[COLOR=#000000]([/COLOR]nextTrack:[COLOR=#0000FF]Number[/COLOR][COLOR=#000000])[/COLOR][COLOR=#000000]{[/COLOR]
[COLOR=#000000]var[/COLOR] nextTile; [COLOR=#808080]// This will become the object returned by the getObject function[/COLOR]
[COLOR=#000000]var[/COLOR] getNextTile:[COLOR=#000000]Function[/COLOR];
getNextTile=trackDb[COLOR=#000000][[/COLOR]nextTrack[COLOR=#000000]][/COLOR].[COLOR=#000080]getObject[/COLOR]; [COLOR=#808080]// reference to the getObject function held in trackDb array[/COLOR]
nextTile=getNextTileCOLOR=#000000[/COLOR]; [COLOR=#808080]// Perform getObject function to return a new track object[/COLOR]
addChildCOLOR=#000000[/COLOR]; [COLOR=#808080]// puts the nextTile on the stage[/COLOR]
[COLOR=#000000]}[/COLOR]
[/LEFT]
[/FONT]
But I get this strange error-
ActionScript Code:
[FONT=Courier New][LEFT]VerifyError: [COLOR=#0000FF]Error[/COLOR] [COLOR=#808080]*#1107: The ABC data is corrupt, attempt to read out of bounds.*[/COLOR]
at TrackContainer/updateTrack[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR]
[/LEFT]
[/FONT]
Anyway, what’s the best way to store a function in an array which returns a new object?
Blah, hope that made sense. Any help is appreciated,
Ben :puzzled: