Hey,
I am a bit rusty on my flash, but not on my C++ or PHP. I am trying to get my movieclip to move on the x axis when a button is clicked and when that movieclip is clicked it dissapears. Pretty simple program, so I don't know what I am doing wrong. I am rewriting a program from c++ into AS3. I do this
var mymc:MovieClip = new MovieClip;
mymc.addEventListener(MouseEvent.CLICK, afunction);
function afunction(event:MouseEvent):void
{
mymc.x = +2;
mymc.visible = false;
}
I am pretty sure my problem is that I need to put the mymc.x = +2; code within the movie clip, so it runs when the movieclip runs and when someone clicks on the movieclip it will run the function afunction to make it invisible. Am I correct in my assumption?
in as3 we dont use +2 for moving a movieclip, it would be something like += 2 if you wanted to move it constantly by two, but it would have to be a enter frame handler, If you want to simply movie it to a destination:
var mymc:MovieClip = new MovieClip;
mymc.addEventListener(MouseEvent.CLICK, afunction);
function afunction(event:MouseEvent):void
{
mymc.x = 100;
mymc.visible = false;
}
if you want it to look good, i suggest looking into greenstock, the as3 tweening engine. Its really easy to use here's an example:
TweenLite.to(mymc, 3, {x:100});
you instance your movieclip you want to move "my mc", then state the duration of the tween "3" and then the x value you want to tween the object to "[x:100]"
var mc:MovieClip = new MovieClip();
mc.graphics.beginFill(0x00FF00);
mc.graphics.drawCircle(0, 0, 30);
addChild(mc);
mc.x = 150;
mc.y = 150;
mc.addEventListener(MouseEvent.CLICK, onClick);
function onClick(evt:MouseEvent):void{
evt.target.x += 20;
//evt.target.visible = false; //If you want visible false
}
+=2 means we are increaseing x position 2 when we click
+2 means we are giving x position means like this mc.x = 2
North America
Europe, Middle East and Africa
Asia Pacific