这是我将数据添加到数据库的代码。
stop(); //add a stop function too!
var gameOver: Boolean = false;
var mainSpeed: Number = 10; //how fast the main guy can move
//BULLET TIMING VARIABLES
var cTime: Number = 0; //the amount of frames that has elapsed since last bullet shot
var cLimit: Number = 12; //amount of frames needed to shoot another bullet
var shootAllow: Boolean = false; //whether or not main can shoot
//ENEMY TIMING VARIABLES
//how much time before another enemy is made
var enemyTime: Number = 0;
//how much time needed to make an enemy
//it should be more than the shooting rate
//or else killing all of the enemies would
//be impossible :O
var enemyLimit: Number = 50;
//showing the amount of enemies that have been added to the stage
var enemyTotal: Number = 0;
//the player's score
var score: Number = 0;
//this movieclip will hold all of the bullets
_root.createEmptyMovieClip('bulletHolder', _root.getNextHighestDepth());
onEnterFrame = function() { //this function will run every frame (needed for moving the character
if (Key.isDown(37) || Key.isDown(65)) { //if the "A" key or Left Arrow Key is Down
bat._x -= mainSpeed; //then the move the guy left
}
if (Key.isDown(38) || Key.isDown(87)) { //if the "W" key or Up Arrow Key is Down
bat._y -= mainSpeed; //then move the guy up
}
if (Key.isDown(39) || Key.isDown(68)) { //if the "D" key or Right Arrow Key is Down
bat._x += mainSpeed; //then move the guy to the right
}
if (Key.isDown(40) || Key.isDown(83)) { //if the "S" key or Down Arrow Key is Down
bat._y += mainSpeed; //then move the guy down
}
//keeping the main character within bounds
if (bat._x <= 0) {
bat._x += mainSpeed;
}
if (bat._y <= 0) {
bat._y += mainSpeed;
}
if (bat._x >= 500) {
bat._x -= mainSpeed;
}
if (bat._y >= 500) {
bat._y -= mainSpeed;
}
if (Key.isDown(32) && shootAllow) { //if the space bar is pressed
var bulletID: Number = Math.random(); //create a variable that we'll use at the bullet's id
//then attach a bullet to the stage
bulletHolder.attachMovie('fire', 'Bullet' + bulletID, _root.getNextHighestDepth());
//setting the coordinates of the bullet to be the same as the main character
bulletHolder['Bullet' + bulletID]._x = bat._x;
bulletHolder['Bullet' + bulletID]._y = bat._y - 70;
bulletHolder['Bullet' + bulletID].onEnterFrame = function() {
//giving the bullet some actions
this._y -= 50; //moving the bullet
if (this._y < -1 * this._height) { //if the bullet goes off stage
//then destroy it
this.removeMovieClip();
}
//checking if the game is over
if (gameOver) {
//destroy this guy if the game is over
this.removeMovieClip();
}
}
shootAllow = false;
}
cTime++; //increment the time
if (cTime == cLimit) { //if enough time has elapsed
shootAllow = true; //allow shooting again
cTime = 0; //reset the time
}
enemyTime++; //incrementing time for enemy
if (enemyTime == enemyLimit) { //if enough time has elapsed
_root.attachMovie('thug', 'en' + enemyTotal, _root.getNextHighestDepth()); //then add the enemy
//setting it's coordinates
_root['en' + enemyTotal]._x = int(Math.random() * Stage.width); //randomly within the boundaries
_root['en' + enemyTotal]._y = -50; //sets this offstage at first
_root['en' + enemyTotal].onEnterFrame = function() { //then give it some functions
this._y += 5;
//run a loop checking if it's touching any bullets
for (var cBullet: String in _root.bulletHolder) {
//if it's touching the bullet
//we have to use coordinates because hit testing doesn't seem to work
if (this._y >= _root.bulletHolder[cBullet]._y - 50 && this._y <= _root.bulletHolder[cBullet]._y) {
if (this._x <= _root.bulletHolder[cBullet]._x + 25 && this._x >= _root.bulletHolder[cBullet]._x - 55) {
//then destroy this guy
//this is where I tried to make it work but
//it just change the movieclip but not removed it
this.gotoAndStop(2)
if (_root.thug.frame = 2) {
_root.thug.removeMovieClip();
}
//and destroy the bullet
_root.bulletHolder[cBullet].removeMovieClip();
//up the score
_root.score += 5;
}
}
}
//hit testing with the user
if (this.hitTest(_root.bat)) {
//set the game to be over and go to lose screen
gameOver = true;
gotoAndStop(2);
}
//checking if the game is over
if (gameOver) {
//destroy this guy if the game is over
this.removeMovieClip();
}
}
enemyTime = 0; //reset the time
enemyTotal++; //add 1 more to the amount of enemies total
}
//updating the score text field
txtScore.text = 'Score: ' + score;
}
当我运行此代码时,会出现错误消息
必须声明标量变量@tell
为什么会收到这样的错误消息?我的代码错了吗?你能帮我摆脱这个问题吗?
这是我收到的错误消息:
答案 0 :(得分:2)
您需要更改第3个参数。
更改cmnd.Parameters.Add("@tel", SqlDbType.NVarChar).Value = tel;
到
cmnd.Parameters.Add("@tell", SqlDbType.NVarChar).Value = tel;
您声明的sql中的参数名称不同
答案 1 :(得分:1)
似乎有一个拼写错误,它应该是@tell
(注意加倍l
)。