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

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).

Related

How to set dynamic text to a variable?

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...";
}
}

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.

How to Use .as Exported File from PhysicsEditor

The question was here for a long time with bounty and no satisfying solution for me. I erased the first post and am posting instead a question that can be answered quickly with a yes or no so I can proceed with my doings.
If you could answer it really fast before it's deleted by "not a good question". Is using a custom shape from PhysicsEditor to Nape the same as doing it with Box2D? (ofc changing syntax)
If you could then give a look in that link then say it's the same process in Nape that'll be enought thanks.
I ask this because I found the Box2D tutorial easier to follow so far.
public var floor:Body;
floor = new Body(BodyType.STATIC);
var floorShape:PhysicsData = new PhysicsData();
floor.shapes.add(floorShape); // Error: Implicit coercion of a value of type PhysicsData to an unrelated type nape.shape:Shape.
floor.space = space;
Update:
According to a comment on this blog post, it sounds like recent versions of Nape have broken compatibility with the physics editor. Specifically, the graphic and graphicUpdate properties no longer exist on body objects. The solution suggested is to remove references to those properties.
I'm not in a position to be able to test this, but you could try updating the createBody method of your floor class as follows:
public static function createBody(name:String /*,graphic:DisplayObject=null*/):Body {
var xret:BodyPair = lookup(name);
//if(graphic==null) return xret.body.copy();
var ret:Body = xret.body.copy();
//graphic.x = graphic.y = 0;
//graphic.rotation = 0;
//var bounds:Rectangle = graphic.getBounds(graphic);
//var offset:Vec2 = Vec2.get(bounds.x-xret.anchor.x, bounds.y-xret.anchor.y);
//ret.graphic = graphic;
/*
ret.graphicUpdate = function(b:Body):void {
var gp:Vec2 = b.localToWorld(offset);
graphic.x = gp.x;
graphic.y = gp.y;
graphic.rotation = (b.rotation*180/Math.PI)%360;
}
*/
return ret;
}

Trace and String Not Working

I'm trying to test some strings but trace outputs nothing. I was using Flash CS6, then I installed Flash CC then everything was fine. But then I created another loop now the same thing. Here's my code:
for (tempNum = lastCharNum; tempNum <= 7; tempNum++) {
trace(tempNum); // this outputs nothing
if (arr[tempNum] != String.fromCharCode(9)) {
firstCharNum = tempNum;
trace(firstCharNum); // this outputs nothing
}
}
I tried:
for (tempNum = lastCharNum; tempNum <= 7; tempNum++) {
txt.text = String(tempNum); // this doesn't make change to the textfield
if (arr[tempNum] != String.fromCharCode(9)) {
firstCharNum = tempNum;
txt.text = String(firstCharNum); // this doesn't make change to the textfield
}
}
Same thing, nothing happens.
Make sure "Omit Trace Statements" is not checked in the the publish settings. If its not checked, try File>Publish and Control>Test Movie>In Flash Professional to see if you get different results.

If two sprites are visible, do something (AS3)

I'm creating a memory like game. I built all the desktop, the cards generation. I now have two cards of each.
I'm trying to do the pairs delete system.
my function to show the color to find looks like this :
private function onClick(e:MouseEvent):void
{
if (vueDos)
{
vueDos = !vueDos;
faceCarte = new Sprite();
faceCarte.graphics.lineStyle(2,0x000000,.5);
faceCarte.graphics.beginFill(clr);
faceCarte.graphics.drawRoundRect(8,8,this.width - 16, this.height - 16, 10,10);
faceCarte.graphics.endFill();
var _t:TextField = new TextField();
_t.selectable = false;
_t.antiAliasType = "advanced";
_t.autoSize = "left";
_t.defaultTextFormat= new TextFormat(maFont.fontName,24,0x000000);
_t.text = couleur;
_t.x = (this.width - _t.width)/2
_t.y = (this.height - _t.height) >> 1;
faceCarte.addChild(_t);
faceCarte.cacheAsBitmap = true;
this.addChild(faceCarte);
}
if(!vueDos)
}
Does it exist a function wich see if the color of the card is visible (faceCarte), and limit the visibles carte to two then removeChild faceCart.
Thank you in advance
You have to make such a function yourself. It'll be better to assign a couleur property to the card itself, instead of putting it into the TextField and forgetting. This way you'll be able to open first card, get that property, then open second card and compare that one's property with what you received, if match, both cards will be removed.