Skip navigation
Currently Being Moderated

Creating a simple android/iphone game in flash-- having trouble

Oct 19, 2011 6:02 PM

Tags: #as3 #android #ios #actionscript3

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?

 
Replies
  • Currently Being Moderated
    Oct 20, 2011 1:20 AM   in reply to the_missing_link

    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]"

     
    |
    Mark as:
  • Currently Being Moderated
    Oct 20, 2011 1:36 AM   in reply to gotoAndHelp ( please )

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points