ActionScript 3.0 issue

Started by
4 comments, last by tburns517 8 years, 5 months ago

For a Flash Game Development course I am taking I am supposed to modify an Asteroids-type game. Our instructor has given us a lot of code to play around with, and I am currently working on including some meters to display the score, lives, level, and energy. The problem is, regardless of what I have tried, I cannot get the new meters to work with the game. The original scoring, lives, and level meters work, so I am not sure what the issue is. Here is what the instructions say that were also given to us:

Note that each movie clip meter has a nested movie clip inside it. The level, score, and lives meters have a text field movie clip object named 'mcItem'. The dynamic text field resides within the mcItem movie clip; and it has its own name: txtAmount. So, for example, to drive information to these meters, your code will look similar to this: levelMeter.mcItem.txtAmount.text = 3;

I am calling the movie clips, for example, as follows: private var livesMeter:LivesMeter = new LivesMeter();

Then going in and trying to use it: livesMeter.mcItem.txtAmount.text = 5;

Doing multiple tests on this, it does not cooperate with the code. I've double checked all of the instances within the movie clip, and they all look correct. I feel like I must be missing something simple, any ideas?

Advertisement
Do you have "addChild(livesMeter);" ?

http://www.danfergusdesign.com/classfiles/oldClasses/VCB331-richMedia1/exercises/addingChildren.php

Thank you Nypyren! That did the trick. Now I have another weird issue happening. The initial score meter will display the score going up by 100s. When the game starts, my added meter starts at 0 just like the original score meter. When I score, my meter changes to 00 while the original meter changes to 100. Any reason why it would be leaving the first digit out? It does it beyond 1000 as well.

It sounds like your text field isn't wide enough to display the full value. Can you manually increase the width and see if that helps?

If not, then showing us some code always helps (if you're allowed to) :)

It sounds like your text field isn't wide enough to display the full value. Can you manually increase the width and see if that helps?

If not, then showing us some code always helps (if you're allowed to) smile.png

I believe I can share the code, if not, oh well. rolleyes.gif

For example with the score (if you are viewing the code), I create it starting on line 172. Disregard the other score creation, that is left for testing purposes. On line 187 is where the score updates. Below is some of the code I am working with in case you don't want to go in and view the files:


private var gameScore:Number;
private var scoreMeter:ScoreMeter = new ScoreMeter();

public function createScoreDisplay() {
        addChild(scoreMeter);
        scoreMeter.x = 350;		
        scoreMeter.y = 3;		
        updateScore();
}

public function updateScore() {
	scoreMeter.mcItem.txtAmount.text = String(gameScore);
}

EDIT: A few other things I am working on are fixing the mouse follower (doesn't fixate on the mouse when still) and collision detection, which I am having difficulty implementing. Any additional help would be greatly appreciated.

I finally got it to work. All I had to do was go in and select the Embed options, then select All. I'm not sure why that is, but I'm glad it finally works. My next issue lies in the movie clip that controls the ship's energy. I currently have this within the checkCollision function:


if (barMeter.currentLabel == "start") {
	barMeter.currentLabel == "hit1";
}
else if (barMeter.currentLabel == "hit1") {
	barMeter.currentLabel == "hit2";
}
else if (barMeter.currentLabel == "hit2") {
	barMeter.currentLabel == "hit3";
}
else if (barMeter.currentLabel == "hit3") {
	barMeter.currentLabel == "hit 4";
}
else if (barMeter.currentLabel == "hit4") {
	barMeter.currentLabel == "hit5";
}
else (barMeter.currentLabel == "hit5") {
	barMeter.currentLabel == "dead";
	shipHit();       // destroy ship
}

When the game starts I set the currentLabel to "start" but that doesn't seem to do the trick. Am I doing this the wrong way?

EDIT: I seem to be figuring out the problems as soon as I post them. I started using gotoAndStop, and that does the trick, however, the starting frame won't stay at the full meter, and it will just move back down to the original position. I'm not sure why this is.

This topic is closed to new replies.

Advertisement