Move a movieclip with every click

Hello

I would like to create a mini game in my game. The purpose of the mini game would be:

To push a cow into a truck by quickly clicking with the mouse. If you're not fast enough, the cow is back to its point of origin.

So I think I need to create the movieclip cow and show the coordinates x something and there something.

Then indicate the code that whenever the player clicks, the movieclip will y + 1.

BUT every 0.5 seconds the movielcip of y-2 (except if it is original of coordinates).

And tells the code that, when the movieclip of cow is at x.somethingelse and y.somethingelse, the puzzle is completed.

Now... Finally and above all... How can I do?

It would be something like this? :

cow = new cowMovieclip;
addchild(cow);
cow.x = 0;
cow.y = 0;


cow.addEventListener(MouseEvent.CLICK, push, false, 0, true);


public function push(e:MouseEvent):void{
// I don't think it's like that
cow.x = +1;
cow.y = +1;
}


if (cow.y = 30){
allPuzzles.room.cowPushed = true;
}

And there is the code indicating that the cow for goes-1 if the Player do not click, but I don't quite know how to put this...

So nothing works with this code, so I guess I made a lot of mistakes.

Can you help me?

Thank you very much for your help,

There is another error in the code

if (cow.y = 30)

should be

If (cow.y is 30);

Maybe you have another ones in your code that causes the disorder.

BTW: setTimeOut is considered to be reliable even less then the timers when it comes to actually measure sth.

The code you provided rewriteen with a timer:

import flash.utils.Timer;

import flash.events.TimerEvent;

import flash.events.MouseEvent;

var clickTimer:Timer = new Timer (500);

var cowClicked:Boolean = false;

clickTimer.addEventListener (TimerEvent.TIMER, clickTimeHandler);

clickTimer.start ();

cow.addEventListener (MouseEvent.CLICK, clickHandler)

function clickTimeHandler(e:TimerEvent):void {}

If (! cowClicked & cow.x > 0) {}

Cow.x-= 5;

}

cowClicked = false;

}

function clickHandler(e:MouseEvent):void {}

cowClicked = true;

Cow.x += 5;

}

Tags: Adobe Animate

Similar Questions

  • Move two objects with a click, without grouping?

    Hello

    The problem is simple, I have three objects (two of them are related images) in the following order: images (bottom) - path of squares (middle) - (on top)

    I would like to move the images only by clicking on one of them without each other, grouping if I combine all the images they would be both on top of the square, I don't want that. I want to preserve order.

    So in other words I would like to "bind" the two pictures togheter, just like in photoshop, click on one - move two

    Is this possible?

    Thank you guys.

    ogutuie,

    In addition to say Steve, (or) if there is a reason to have and keep them together, you can:

    (1) click on top, then right-click and click next object below or last object below, then ShiftClick to have selected both select them only once.

    After that, you can move them together, or you can

    (2) select > Save selection and give them a name.

    After that, you can move the selection by clicking in the Select > selection.

    Or you can select through the layers palette.

    Hi Steve. Fall with severe wetness.

  • AE crashes with every click

    I'm a bit this year with After Effects issues, but today, this one will do the rest of my fall of hair out.

    I create a video for a client, it is 960px wide, 480px high and far that I imported only 2 audio files from a collection of Video CoPilot and 20 png graphics. The video uses the target of this plug-in from VideoCoPilot (I've used several times before, with success). Last night, I was able to get a preview of the video and watch them fly in all the graphics at full resolution. This morning, I imported an audio file more (belonging to the same group, music, I used before) and now AE literally hangs on every click that I do.

    I open AE without problem, the file is located in the Welcome screen, I open it and all seems fine, I click anywhere in AE and I get the blue circle of "wait a second" in Windows 7, if I click once again, AE melted in with the overlay of white (like if it crashes). After 3-5 minutes, the white overlay goes but I never lose the blue circle and if I click anywhere, the overlay of white is back. If I click to close the program that he told me that AE crashes and to close the program or wait for it to respond. The only thing I could do is to check the version number and get once in the preferences.

    Quick responses, I got on Twitter from @AdobeAE brought me here, initially, they suggested to this page: http://forums.Adobe.com/thread/543440 where I double everything checked and made a few adjustments. Unfortunately, nothing changed in these links. I've always had a difficult time in video preview and the RAM Preview has always been a thorn in my editing process, but now I am unable to proceed at all with a large date limit arises in less than 48 hours.

    Data sheet: CS4 Master Collection, Windows 7, i7 processor, 8 GB of memory (door FX6840)

    Thanks for any help you can provide, this one has me totally baffled.

    Here are a few things that come to mind:

    Have you installed the After Effects CS4 (9.0.3) update? This update solves a lot of problems.

    Using OpenGL? If so, don't. See this document.

    If you have Aero enabled in Windows 7, you can turn it off.

    Try without the audio file that you added just before the problem arose. Try without target course. Make sure you have the current version of msot of target course.

  • movement of character with mouse click

    It is an online MMO game / world. So it must be good.

    Hi guys. I'm really happy that I got this works as I am a neebie to AS3, but learn to love its simplicity. My problem is not my AS3 but my math.

    I click on the mouse and the movieclip goes up to the x position of the mouse. However, it is in a sense what to say: down and to the right.

    I don't have to it go in all directions depending on where you click. I guess it has to do with the comparison x and y positions of mouse and mc - IE: If one is larger than the other, so you can tell where both are positioned and then put the code in. I'm wrong and at - it someone hace some code like this flying around me?

    import flash.display.Stage;
    import flash.events.Event;

    stage.addEventListener (MouseEvent.CLICK, myClickReaction);

    function myClickReaction (e:MouseEvent): void {}

    sunny.gotoAndPlay ("runback")
    Sunny.x = root.stage.mouseX
    Sunny.y = root.stage.mouseY
    addEventListener (Event.ENTER_FRAME, onEnterFrame);
    }
    function onEnterFrame(event:Event):void {}
    var xDistance:Number
    var yDistance:Number
    MC in increments of 5 until it reaches the mouse - mc (ie the distance)
    Sunny.x += 5;
    Sunny.y += 5;
    xDistance = root.stage.mouseX - sunny.x
    trace (xDistance)
    If (xDistance < = 0) {}
    trace ("Works")
    sunny.gotoAndPlay ("static")
    removeEventListener (Event.ENTER_FRAME, onEnterFrame);
    }
    }

    As I said, my code does not detect when stop well. Perhaps, your the best fact. But your code is not as optimal as mine regarding the places where variables are declared and calculated (in particular, angle and useless statement of distanceY and distanceX). You should review this part.

  • Is there a way to create a graph that grows with every click of a button?

    We have a client requests a page that would allow people to click on a button saying that they are "Taking a Stand Against Domestic Violence" and hold that there is a counter indicating the number of people who have clicked on it.

    They asked a sort of Visual graphic to go with it. Is there a widget out there like that? Or does anyone have suggestions?

    There is nothing to specifically for the Muse who does this, but if you are looking for on the web, you might find some survey services although the embed function provided and use the Insert HTML code in Muse to integrate. Personally, I'm still heating to do this kind of thing because they are so easy to handle and end up with unrealistic figures.

  • Can rotate us items separated with one click (Jquery)

    Hi guys,.

    I am trying to create an interactive dial. It contains three layers. Ideally, I'd like that the end user to be able to drag each layer separated from the dial and turns each separate to 60 degrees on each drag element.

    Otherwise, I wish that each separate element (the different layers in gray below), once clicked, to rotate 60 degrees.

    So far, I've been able to turn each element on a click once, but I'm unable to solve how to make that happen again and again with every click.

    Here is my code in step:

    (function ($) {}

    $. fn.rotate = function (degree, maxDegree) {}

    //...

    };

    (} (jQuery)); <-call

    Here is my code element:

    SYM. $(«_2dial») .animate ({'down': "60px banner"},)

    {

    Duration: 2000,

    step: function (now, fx) {}

    SYM. $("_2dial") .css ({"-moz-transform": "rotate("+now+"deg)", "})

    ' - webkit-transform ":"rotate("+now+"deg) ",

    "- ms-transform": "rotate("+now+"deg)",

    ' "- o - transform":"rotate("+now+"deg)"}); "

    }

    (}, 'linear');

    My file can be downloaded here:

    http://www.filedropper.com/edge-dial-files

    Thanks for the help.

    Here are the dial. I wish that each of the gray circles to rotate separately on click (each segment will have text on it).

    dialedge.png

    Hello

    I posted an example of dragging a wheel and snap the ends directed to the bottom of the page in the link below. It is 2 years old, but the calculation has not changed since then. I also highly recommend using GSAP for any animation based on the code, rather than jQuery animate. You can download GSAP here: GreenSock | GSAP. And you can import the code of the script of Edge panel. If you master the GSAP library, your life will change for the better!

    Rub a wheel and turning a pot with edge animate!

    Example:

    http://www.timjaramillo.com/code/edge/drag_rotate/test.html

    Source:

    www.timjaramillo.com/code/Edge/_source/drag_rotate_wheel.zip

    About the rotation-click does not, I would start by moving all the functional code to the Stage.compositionReady event (instead of keep this code on each dial. Reason being that each click event, your values are to be replaced. In my sample pseudo-device code below, when you click on a dial, you call a 'rotateDial1', 'rotateDial2' func (create a function for each dial), etc., that you would create in the event Stage.compositionReady. This function would be track/game to your var of rotation for each wheel.

    Pseudo code:

    Add to Stage.compositionReady event-

    var _dialRotationAmount = 60; / / angle you want to rotate on every click

    var _rotationDial1 = 60; / / rotation track for call 1. Create a variable for each of your dials

    called on the click event of the dial 1. Making a function for each of your dials, change the values inside the function to match your dial #.

    sym.rotateDial1 = function() {}

    Add to the rotation value

    _rotationDial1 += _dialRotationAmount;

    Rotate the dial

    var _dial1Symbol = sym.$("_1dial");

    TweenMax.to (_dial1Symbol, 1, {rotation: _rotationDial1, ease:Power1.easeOut});})

    }

  • I want to move a large number of photos but don't want to unique, click each photo. I know there is a simple control function that allows to select groups of files with ' two'clicks ', as opposed to the selection of each file. Suggestions?

    I want to spend a lot of photos (they are in order) but and do not want to have to click to move each photo. I know there is a simple control function that allows to select groups of files with ' two'clicks ', as opposed to the selection of each file. Suggestions? I know it's apple 101, but I don't remember what order to press the button command, or shift, or other. Thank you

    Select the first file, then hold down the SHIFT key, and then click the last file. Or, select any file in the folder and then press command + A

  • TextField in MovieClip crashes MouseEvent.CLICK on even vector background with mouseChildren = false

    I'm trying to put in place a button in Flash/AS3, but a TextField poses problems with it, no matter what I do. I wonder if anyone has any ideas.

    I have a MovieClip called TabSelector. Inside the TabSelector , there are two layers. The first layer has a TextField called lblLabel. The second layer has a MovieClip named background , which is an instance of TabBackground.

    TabBackground is a MovieClip that contains a single vector shape. It has two frames (States 'active' and 'no hurry' representative), the vector of a different color in each image.

    To keep the object TextField interfering with the click event handler, I of the TabSelector mouseChildren property to false. Now I did it with a dozen of personalized in this project and it has always worked well, but for this button, if I click anywhere in the region which occupies the TextField, TabSelector does not save a click at all (it still works if I click on the edge where does not reach the TextField). I also tried mouseChildren setting set to true and lblLabel.mouseEnabled to false, but the same problem occurs.

    The only difference between this button and all the other buttons I've done is it has experience of vector and other imported PNG backgrounds (i.e. bitmap).

    A TextField causes a hole in the vector behind her graphics if you set its property mouseEnabled false?

    It was relevant to ask if vectors would act differently from bitmaps and Yes, they do, and there is proof. It was the point of it. I tried also illustrate just how to embed a form within a clip to fix the problem. I have not read that you have assigned the listener outside most clip however. I still disagree with mouseChildren. Chances are your problem was elsewhere.

    It happens to the best of us, especially on complex interfaces. Makes you want to start assigning tracing instructions, and then click handlers objects near him to see what it covers. Chances are it is a TextField gone wild elsewhere. Allowing borders or background on TextFields close it can reveal what it covers.

    By the way that event.target gives it to the child, but you can always get the first object clicked using events. currentTarget. Keep this in mind. I never use event.target because you never know what object will fire at the time where things contain several items in the view. event.currentTarget always will return the parent clip most who can respond to your click.

    Finally setting cacheAsBitmap on the TextField object simply a bitmap in memory, and so would act exactly like any other image bitmap, including issuing MouseEvents, except disabled via mouseChildren = false or mouseEnabled = false.

  • receive the error message with every new open tab

    Whenever I open a new tab, I get a popup error message. I have screen shots that can be granted.

    At first, I thought it was a mistake to Java, but I've uninstalled and reinstalled Java.

    There are two error messages which read:

    [JavaScript application]
    evalInSandbox:Error: Permission denied for <https://facebook.com> create a wrapper for the object of class UnnamedClass.

    [JavaScript application]
    Error: Permission denied for <https://facebook.com> create a wrapper for the object of class UnnamedClass

    So I clicked on help > troubleshooting information and choose Reset Firefox.
    Now I get a new error message with every new tab open.

    [JavaScript application]
    Error: syntax error

    Please tell us how to do this.
    Thank you
    JudyLeeThurber

    1. In the address bar, type Subject: config and press enter. The subject: config "this might void your warranty!" warning page may appear.
    2. Click on I'll be careful, I promise!, to continue on the subject: config page.
    3. Type browser.newtab.url
    4. Double click on the first result, a new window should now display.
    5. Type of topic: newtab in the area.
    6. Click ok and load a new tab. It now works of mireille?
  • I can't do the command 'Open with' right click - in windows 7

    I can't do the command 'Open with' right click - in windows 7.

    It applies to all files, whenever I want to 'open with' a program there is a line that stood saying
    "This file doesn't have a program associated with it for performing this action. "Please install a program or... -" and so on
    This applies to all of the files from my laptop every time I tried a file "open with." Is it possible to fix it? I really want to look at the issue, because these things make me really frustrated.
    Please help me, thanks.

    The REG fix available in this article should solve the problem.,.

    'Open with' or the option "choose program...". ', hence the error:
    http://WindowsXP.MVPs.org/openas.htm
    [For PC Windows 7, download and run openas_win7.reg and run it.]
  • Question Windows Spider solitaire game flashes and I can't move cards unless I have click or drag a lot of times.

    Original title: Spider Solitaire not good

    Spider Solitaire is flickering, and I can't move cards unless I have click or drag a lot of times.  The simple answers please because I am not technical minded.

    Hello

    ·        This only happens with solitaire and spider or other games as well?

    ·        You did changes to the computer before the show?

    Method 1: I suggest you to put the computer to boot and see if the problem still occurs.

    http://support.Microsoft.com/kb/929135

    Note: after a repair, be sure to configure the computer to start as usual as mentioned in step 7 in the above article.

    Method 2: Update the video card driver and check if this solves the problem.

    http://Windows.Microsoft.com/en-us/Windows7/update-a-driver-for-hardware-that-isn ' t-work correctly

    Method 3: The problems of the game performance

    http://Windows.Microsoft.com/en-us/Windows7/fixing-game-performance-problems

  • Impossible to move the camera with the touchpad in the games while moving in Windows 8?

    I've seen this happen on two Toshiba laptops now, I can't move the camera with the touchpad in games like TF2 while I also move with WASD keys. The problem disappears when I use an external mouse, even if, I was wondering if anyone else has this problem, and if someone has solved. I disabled the Edge slides in the Synaptics Control Panel if it helps.

    Thank you in advance! :)
    Edit 15/5: I did more research, and it seems that there is a feature called "PalmCheck. I am yet to confirm because I'm away from home, but I will as soon as POSSIBLE.

    Solved! The feature was PalmCheck Synaptics Control Panel.

    To fix:
    1. look for 'mouse', click on settings, then 'Mouse' with the mouse icon.
    2. click on device Options.
    3. click on settings.
    4 expand the category of "pointing".
    5. click on PalmCheck, then the small icon of gable beside him.
    6 move the cursor to a Minimum or offshore.
    7. apply, OK, and you're done!
  • How to restrict the movement of movieclip on the stage?

    Hi, I want to spend my movieclip to the left and right, but he moves out of the scene. I want to restrict the movement of X the width of my step.

    This is my code for the movement of movieclip:

    import flash.events.KeyboardEvent;

    stage.addEventListener (KeyboardEvent.KEY_DOWN, moveavatar);

    function moveavatar (event: KeyboardEvent): void

    {

    If (event.keyCode is 39)

    {

    avatarmove.x += 10;

    }

    Else if (event.keyCode == 37)

    {

    avatarmove.x = 10;

    }

    }

    How do I limit the movement of X the width of my step so it won't leave the stage? Thank you.

    You have the registration point in the upper left corner. In my case, I had to focus. If you want to keep as you have, replace with this:

    import flash.events.KeyboardEvent;

    stage.addEventListener (KeyboardEvent.KEY_DOWN, moveavatar);

    function moveavatar(event: KeyboardEvent): void {}

    avatarmove.x = Math.max (0, Math.min (stage.stageWidth - avatarmove.width, avatarmove.x - int(event.keyCode==37) * 10 + int(event.keyCode==39) * 10))

    }

  • How can I enlarge the movie clips? [with pictures]

    There are 9 video clips in each square (object) and the color in each video clip can be changed by mouse click.


    However, if I want one of the spaces enlarge by clicking on it, then I can click on each video clips to change the color.

    How can I do? Can I create another movie clip and cover the place to click to enlarge?

    Please help me! Thank you!!!

    AS2 or AS3? AS2, you can disable the movieclip which is clicked by mc.enabled = false; For AS3, you can either remove the event listener as mc.removeEventListener ("your event type used listener", onClickFunc) or you can add a flag (Boolean variable) you set to false when it was enlarged and use it to check your onClickFunc and decide whether to change the color of a movieclip or not.

  • MovieClip, capturing the click of the mouse on the whole scene

    I made a button in 2 States in a project (completely at designtime) using a movieclip. I have change the State (and search) of the button by switch between frame 1 and 2. The problem is...

    Even if the video I created (and registered in the library) is small, the onMouseUp event is captured by the movieclip anywhere, I click on the stage. Any thoughts?

    Here's the code...

    It is in box 1

    _root. Status_Append ("code running on chassis 1"); display of status information (debug)
    This.base_off. OnMouseUp = function() {}
    _root. Status_Append ("base_off. OnMouseUp"); display of status information (debug)
    gotoAndStop (2);
    }
    Stop();

    It is in the frame 2

    _root. Status_Append ("running on frame 2 code"); display of status information (debug)
    This.base_on. OnMouseUp = function() {}
    _root. Status_Append ("base_on. OnMouseUp"); display of status information (debug)
    gotoAndStop (1);
    }

    RustyT wrote:
    > I did a button in 2 States in a project (completely at designtime) using a
    > movieclip. I have change the State (and search) of the button by switching
    > frame 1 and 2. The problem is...
    >
    > Even if the video I created (and registered in the library) is low, the
    > onMouseUp event is captured by the movieclip anywhere, I click on the
    > stage. Any thoughts?

    onMouseDown and UP have to go with hitTest action. Otherwise it will be global property.
    HitTest, allow to define the specific target of the mouse UP/down of the events.

    --
    Best regards

    Urami

    --


    If you want to send me a message - DO NOT LAUGH at MY ADDRESS

Maybe you are looking for

  • Backlight of the A31

    I have a wonderful A31 who has starting pink screen syndrome. The fluorescent light used to screen the A31 credits that can be ordered or is it a search on ebay-type point? In addition, the inverter could also cause start up pink screen syndrome? Pin

  • Windows Vista/7 OEM (Dell) x 64 Media

    It is possible to purchase x 64 Dell support, if your PC came with an x 86 version of Windows preisntalled?

  • BlackBerry smartphones add contact

    I can't add numbers to my phone can some help me please

  • On stop, office flashes and forces me to do a program in a new window that appears. Has never done this before

    During the shutdown, wallpapers flash at very high speed. Then, a window pops up saying that I need to close a program that is running. I hit the OK button, and another window opens asking if I'm sure I want to put an end to the program. hit Yes, and

  • The AAA command authorization

    I have an ACS 4.0 device. In the shell command authorization set section, you can define authorized or rejected orders (see) and arguments (running-config). I'm limiting users to a set of specific commands. One of the commands is "exit". To my knowle