How to set dynamic text to a variable? - actionscript-3

Im trying out adobe animate for school and until now ive been following a cool rpg game tutorial. but the tutorial ended quicky and now im left on my own browsing the internet. i wanted to add a little star collector feature but the tutorial i found is for flash and i dont know how to use it.
their code is pretty much
money = 0;
onClipEvent (enterFrame) {
if (_root.move_mc.hitTest (this)) {
_root.money++;
this._x = -50;
this._y = -50;
}
}
and i hanged it to
var star:Number = 0;
if(linkMc.hitBoxMc.hitTestObject(overworldMc.starMc1))
{
star += 1;
overworldMc.starMc1.alpha = 0;
}
and it works but now i need to figure out a way to set up a text n the corner telling you how many stars you have.
[link to their image] (https://www.kirupa.com/developer/actionscript/images/textBox_settings.JPG)((((i cant post images yet as i dont have enough points))))
but my version of adobe animate doesnt seem to have the var option! so how do i set up the text?

Try some logic like below. The code is untested, but should be useful to you towards a working solution:
var star :int = 0;
//# create an *enterFrame* function for multiple stars
overworldMc.starMc1.addEventListener( Event.ENTER_FRAME, myClipEvent );
overworldMc.starMc2.addEventListener( Event.ENTER_FRAME, myClipEvent );
overworldMc.starMc3.addEventListener( Event.ENTER_FRAME, myClipEvent );
function myClipEvent( myEvt:Event ) :void
{
//# or... myEvt.currentTarget
if(myEvt.target.hitTestObject(linkMc.hitBoxMc))
{
star += 1; //can be... star++;
myEvt.target.alpha = 0; //# also test replacing *target* with *currentTarget*
//# use String( xxx ) to cast Numeric data type into a Text data type
money_box.text = String(star) + " " + "Stars...";
}
}

Related

Problems with adding Score in text field for AS3

New here and learning flash AS3. I am having a problem with a game I'm working on. I am a teacher and it is a review game. I would like to display the score as part of a text field. At the very beginning I declare the variable:
var wrongScore:Number = 0;
var correctScore:Number = 0;
Then when an object is dragged and dropped I am trying to display an updated score. It is displaying "Number Correct:" and "Number Wrong:" but not giving the value of correctScore or wrongScore.
function left1Drop (e:MouseEvent): void {
if (left1.hitTestObject(leftTarget))
{
left1.stopDrag();
correct.play();
correctScore += 1;
correctScoreText.text= "Number Correct:" + String(correctScore);
left1.removeEventListener(MouseEvent.MOUSE_DOWN, left1Drag);
}
if (left1.hitTestObject(rightTarget))
{
left1.stopDrag();
left1.x = left1StartX;
left1.y = left1StartY;
wrong.play();
wrongScore += 1;
wrongScoreText.text = "Number Wrong:" + String (wrongScore);
}
else
{
left1.stopDrag();
}
}
I am guessing my problem is somewhere in the code below. But I believe I am typing it exactly as I've seen it elsewhere.
correctScoreText.text= "Number Correct:" + String(correctScore);
Thank you in advance for any help you can offer!!!

CreateJs MovieClip Instance name

Hi Guys (sorry for my bad english), I've stuck with this in a week, is it possible to get the movieclip instance name with createJS (I've put the movieclip manually on the stage and I give it an instance name), in AS3 I can use movieclip.name to get the instance name, how can I do that in createJS, when I use this.movieclipName.name it always return null in console log, do You have any suggestion? Thanks for Your help?
#Ferry thank You very much for Your solution. finally I figured it out, We can't get the instance name of the object by myObject.name because the name of the object is not signed previously (it looks like the instance name not same as name in html5). that's why it always giving a null. This is my script to get all the instances name of my objects.
for (var a = 0; a <= maxObject - 1; a++) {
var myObjectName = 'object' + (a + 1);
var myObject = this[arrObject[a]];
myObject.name = myObjectName;
}
Thank you guys for all of your respon.
i solve this problem using:
for (i = 1; i < 6; i++) {
this["m" + i].addEventListener("click", clickme.bind(this));
this["m" + i].hamdy=i;}
so you can use var hamdy to pass any change in clickme funaction.

Use of particle effect

I am using particle effect my game using libgdx. But effect is showing for small time and after that it disappear.But I want to show my effect for long time or in my control.
My code is given below in my game play screen class...
ParticleEffectPool waterEffectPool;
Array<PooledEffect> effects = new Array<PooledEffect>();
ParticleEffect waterEffect;
...
...
waterEffect = new ParticleEffect();
waterEffect.load(Gdx.files.internal("data/runonwater"), Gdx.files.internal("data"));
waterEffectPool = new ParticleEffectPool(waterEffect, 1, 5);
//for(int i = 0; i <= waterEffectPool.max; i++){
PooledEffect effect = waterEffectPool.obtain();
effect.setPosition(150, 130);
effects.add(effect);
and in render method I use it to render
for(int i = effects.size - 1; i >= 0; i--){
PooledEffect effect = effects.get(i);
effect.draw(spriteBatch, deltaTime);
if(effect.isComplete()){
effect.free();
effects.removeIndex(i);
}
}
I have already answered the question in the comments section above but still writing it here so as it can be accepted (as suggested by P.T.)
If you are using particle editor then there is an option weather to set this effect continuous or not. Set continuous as true and problem will be solved .
#P.T. yups you r right. Will remember it from now on :)

actionscript 3 (about ysqu, ydf, and ymo)(making menu)

i am handling with a flash assignment right now.
however, there is trouble from changing as2 to as3
will u know what is the code for as3?
onClipEvent (enterFrame) {
Ysqu = _root.menu._y;
Ydf = Ypa-Ysqu;
Ymo = Ydf/10;
_root.menu._y = Ysqu+Ymo;
updateAfterEvent(enterFrame);
}
thanks so much!!
To know conversions, you must understand them...
addEventListener(Event.ENTER_FRAME, sup);
function sup(e:Evt):void
{
Ysqu = MovieClip(root).menu.y;
Ydf = Ypa-Ysqu;
Ymo = Ydf/10;
MovieClip(root).menu.y = Ysqu+Ymo;
e.updateAfterEvent
}
You will get a warning about updateevent, but it still works.
_y is changed to y. OnClipEvent is changed to addEventListener. _root is changed to MovieClip(root).

ActionScript 3: dynamic text help: scoring for game

I am very new to action script 3, and I am trying to make a very basic game right now. However, no matter how many pages I look at I can't find a working way to get my game to keep score :/.
What I am trying to do is make it so that every 10 seconds, 10 points is added to the score (right now I have it replaces with a key, to see if I could get that to work, but it didn't).
This is the code I am trying to use right now:
var playerScore:int = 0
stage.addEventListener(MouseEvent.CLICK,onclick);
function updateTextFields():void{
playerScoreText.text = ("Player Score: " + playerScore);
}
if(Key.isDown(Key.G)){
playerScore++; //increase playerScore by 1
updateTextFields();
}
playerScoreText is the name of the dynamic text
any help will be greatly appreciated :)
This code was all added in Timeline
I am thinking the problem is most likely something with the creation of the dynamic text, but I am not sure.
Make sure the fonts are embedded properly and that the color of the dynamic text field is not same as the background.
also instead of writing
playerScoreText.text = ("Player Score: " + playerScore);
try this
playerScoreText.text = "Player Score: " + String(playerScore);
It sounds like you want to do something like this with the timer class. Your key code isn't written properly.
var playerScore:int = 0;
var score_timer:Timer = new Timer(10000,0);
score_timer.addEventListener(TimerEvent.TIMER,updateTextFields);
score_timer.start();
function updateTextFields(e:TimerEvent):void
{
playerScore+=10
playerScoreText.text = ("Player Score: " + playerScore);
}