Detecting Rotation Amount to Control Movie Clips

I created a movie clip consisting of a bar and a knob.  When you click and drag the knob, the bar rotates through 360 degrees.  I want to be able to detect the degree of rotation and use that metric to control other movie clips.  The code to make the drag/rotate object work is...
handle.knob.onPress = function(){
handle.onMouseMove = function(){
  var angle = Math.atan2(this._parent._ymouse-this._y,this._parent._xmouse-this._x);
  this._rotation = angle*180/Math.PI;
  this.knob._rotation = -this._rotation;
  trace(angle);
  trace(angle*180/Math.PI);
handle.onMouseUp = function(){
if (this.onMouseMove) delete this.onMouseMove;
I can trace the angle in radians and degrees but I don't know how to extract either value as a variable that can be used in a function to control a separate movie clip.

assign a variable to have the value of the _rotation or angle in your onMouseMove function.   and use that variable's value wherever you like.

Similar Messages

  • How to control movie clips using mause scroller...?

    ....please look
    http://www.nagaoka-id.ac.jp/gallery/gallery.html
    ...how to control movie clips using mause scroller...?

    Hi Ldavinci, I have noticed your posts on that particular
    site before. Just chiming in here... don't be afraid of Flash Help
    menu. There's a wealth of information there and I've found it much
    faster than waiting for a response from the forum. Then if it still
    doesn't make sense, at least you have a basic idea of specifics to
    ask.
    If you search for mouse wheel, you'll see an example under
    the Actionscript 2.0 Language Reference on this topic. That said,
    here's the example:

  • Help with assignment- buttons that control movie clips

    I am pretty new to flash and my professor gave us an assignment with little help or tutorials.
    He wants us to create a SWF that features a house and it's front yard and two buttons.
    One button that says Sunrise, and one that says Sunset.
    When I push the sunrise button, the sun needs to rise above the house and stay there.  When I push the Sunset button, it needs to set- and then a ufo needs to land on the lawn.
    So i think I have a pretty good grasp on the assignment, but the actionscript is throwing me off.  How can I make buttons that will control the sun movie clip to rise- stay above the house, and then set?  The ufo is a whole new matter.   The sunset button should make the sun lower and then a ufo land on the lawn.
    Please help explain/link me to the proper tutorials.   One thing that i'm worried about is that the sun will rise- and then stay above the house even if i click the sunset button.
    Your help is greatly appreciated.

    Well i can think of a few ways to do this.
    Depending on what you have been taught so far you should be able to do this if you know how to make a button, a movie clip, and the basic script for the timeline. ie. play,stop, gotoandplay etc.
    I understand you have been set a task and you want the answer straight away. But i doubt he would have given you anything you couldn't handle. Also I learnt more from trial and error and searching the net than from most of my teachers at coll and uni, It's frustrating i know, but the buzz you get when you finally crack it is amazing. Stick in there!
    That being said i remember the panic I suffered and like to help so here's a thought:
    You could just have the 2 buttons play a basic movie clip. The sky could rotate one way to make the sun rise and add a "stop" in the actions to make it stay there, and to the left to sunset with both images together but not being shown all the time by using a mask. You could even add in the ufo to the clip but this would only work if you added an extra part to the movie so that when the ufo has landed it flys out again and then begins to rotate the sun and moon again. ( buttons would be dissabled during the play modes to avoid chaos) This is just a quick thought. I'm sure there are several ways of doing this depending on how fancy it needs to be.
    If your teacher really has given you no notes on buttons,movieclips and actionscript i would sujest Adobe TV. Nice videos that explain step by step. OR try downloading a tutorial file with buttons and movie clips and look at the coding they use in the file. Thats how i have learnt most of it since finishing Uni.
    Good Luck
    Cobie

  • Simple Button to Control Movie Clip

    Hello,
    I was relatively comfortable with AS 2.0, but am having a
    hard time warming up to 3.0. I feel that this should be something
    simple to find help online with, yet I'm finding it difficult to
    get a simple answer.
    I have a button that is inside a movie clip within another
    movie clip:
    mainMenu_mc > whoBtn_mc > whoButton
    This button appears to work fine controlling a movie clip on
    the same timeline. This is the code so far (on an Actions frame in
    WhoBtn_mc):
    whoButton.addEventListener(
    MouseEvent.CLICK,
    function(evt:MouseEvent):void {
    whoGlow.gotoAndStop("click");
    I have another movie clip on the main timeline that I would
    like to control with this button:
    blackFadeBottom_mc
    What would the code look like for this?
    Any help is appreciated - Thank you.

    Thanks, I was able to place the code on the main timeline and
    get a trace when I clicked on the movie clip instance itself. I
    probably didn't explain what I was trying to do very well, so I
    apologize.
    What I need to do is to control this movie clip that is
    physically placed on the main timeline (fadeBlackBottom) with the
    button that is buried under two other movie clips
    (mainMenu_mc>whoBtn_mc>whoBtn).
    I would like the whoBtn to tell the fadeBlackBottom movie
    clip to (what used to be)
    _root.fadeBlackBottom.gotoAndPlay("play"); This will drop down a
    box that will contain the content of my 'Who' link.
    How can I accomplish this?
    Thanks again,
    Chuck

  • Detecting the end of a movie clip

    Hi,
    Objective: Display a book that the user can turn the pages to
    view more text. I used a tutorial from the web to create the
    turning page.
    Process: On layer 1, frame 1 of the main time line, I put an
    image of a book. On layer 2, frame 1 and also frame 2 of the main
    time line, I put text for the book. I then created a movie clip
    (MC) called PageTurnMC that looks like a page in the book is being
    turned. On layer 3 of the main time line, I put an instance of the
    MC and called it PageTurn. On layer 4 of the main time line, I put
    a button to play the MC and advance to frame 2 called drawer1cont
    (see code).
    //code on the button used to turn the book's page
    on (release) {
    PageTurn.play(); //plays my PageTurnMC
    gotoAndStop("drawer1cont"); //advance to the next frame of
    text
    Problem: I need to detect when the end of the MC before I
    advance to the next frame. I have to use the PageTurnMC many times,
    so it is not possible for me to put the action in the last frame of
    MC. As of right now, my frame 2 text appears as the PageTurnMC
    plays which is not what I want.
    Thanks for any help.

    I just tested it and got my quick example to work. Here are a
    couple of possible areas to double check:
    In the last frame of PageTurnMC, gotoAndStop must reference
    the main movie clip, e.g. _root.gotoAndStop().
    Also, make sure the parameter _root.frameID isn't in quotes
    because it is a variable, not the actual string.
    As I said, I'm not a Flash expert nor do I know the setup of
    your movie, but this should work as long as you have all of your
    references correct. If you can't get it to work, try to trace
    necessary variables to make sure you are accessing the appropriate
    variable.
    The suggestion by nilu_only will also work, but it will waste
    some cycles because you will have to wait for the movie clip to
    end. Here is what I mean:
    Immediately after playing PageTurn, accessing
    PageTurn._currentFrame will return the currentFrame only once. So
    if PageTurn isn't on its lastFrame, your condition statement
    (PageTurn_currentframe == PageTurn._totalframe) will fail and
    gotoAndStop will never be called.
    Instead, you would need to wait for some time and continually
    check the _currentFrame until the condition statement is true, e.g:
    on (release) {
    PageTurn.play();
    while (PageTurn_currentframe != PageTurn._totalframe) {}
    //wait until reaches the last frame
    gotoAndStop ("drawer1cont")
    This approach is likely to be suboptimal since you are
    wasting cycles checking the current frame instead of just having
    the movie let you know when it has reached the last frame.
    Depending on how Flash handles that while statement, you could have
    serious slowdown from that while statement. And since Flash doesn't
    have a sleep() function, you would have to do some sort of
    setTimeout() to slow down those checks. Either way, I would venture
    to say this approach is better off avoided.

  • How to detect the end of a movie clip:  what eventListener to use?

    I'm doing a rather fancy button with up,down,rollover,rollout,and static states, something the standard flash button structure isn't capable of as far as I can tell, and believe me, I've tried it.
    Here's the setup:  My main timeline has a series of frames with stop(): scripts, and each frame has a movie clip representing what should happen during that state:  still, rollover, rollout, mousedown, mouseup
    I can't get the mouseup event  to work.
    Here's what I've tried so far that doesn't work:
    1. in the imbedded movieclip, no script at the end.  Result: This just loops the embedded clip.
    2. in the imbedded movieciip, put gotoAndPlay("NextFrame"), where "NextFrame" is the label in the root movie where I want to go. result: loops clip
    3. in the imbedded movieciip, put root.gotoAndPlay("NextFrame"), where "NextFrame" is the label in the root movie where I want to go. result: error
    I think what I need to do is write an eventListener for the root actionscript, but I don't know what event to listen for. 
    What event is thrown when a movieclip finishes playing?
    :<)McFrisco

    You have to create your own mechanism(s) for detecting the end of a movieclip being reached.  You can either build code into the end of the clip itself, possibly dispatching an event that is being listened for by a containing timeline, or you could continuously monitor the currentFrame of the clip to see if it equals the totalFrames value.

  • Controlling movie clip on timeline

    Hi, newbie question.
    If I put a movie clip on the main time line and that movie
    clip has its own time line, is there a listener I can use to detect
    when the movie clip I put on the main time line is finished
    (reached its last frame).
    Thanks.

    Here's the simplest way:
    Give the movieclip the instance name "myMC".
    Then put this code on your main timeline:
    onEnterFrame = function () {
    if (myMC._currentframe == myMC._totalframes) {
    DO THIS;
    onEnterFrame = null;
    In this function, every time a new frame turns over, it will
    check if myMC has reached its end. When it does, it will execute
    the commands I've written as DO THIS, and stop making this check.
    Let me know if you run into any problems.

  • Controlling Movie Clip with actionscript Question

    Dear All,
    I have a movie clip named A which inside this movie clip
    there is another Movie clip named B and inside B there is a listbox
    component.
    Inside Movie clip A there are 20 frames which at frame 10
    there is a stop() script.
    My question is how to control Movieclip A to run
    gotoAndPlay(11) from MovieClip B when there is a click action to
    the listbox?
    Please Advise,
    Ozhee

    if A is on the _root timeline from anywhere in your _level0
    swf you can use:

  • Controlling Movie Clip with as3

    I try to controll my mc. I want put one MovieClip to other.
    i use next code:
    box_mc.addChild(pic_mc);
    but its not working.
    box_mc this is the a box movie clip, in this mc i want put my pic_mc.

    In addition to what dmennenoh said,
    DisplayObject's x and y properties are preserved no matter parent. In your case, it seems, original position of pic_mc is not 0/0. So when you place it inside the box - x and y are the same but now they are RELATIVE TO BOX. So, on screen it looks like it is outside the box but it is inside except that box's x and y are added.
    For instnace, if the original coordinates are pic_mc.x = 200, pic_mc.y = 100 and box_mc.x = 50, box_mc.y = 20, when you add pic_mc as a child, it will have the came x and y but relative to box_mc (not its original container) and on the screen it will look like it is on x = 250 (box_mc.x + pic_mc.x) and y = 120 (pic_mc.y + box_mc.y).
    box_mc's dimensions also change IF pic_mc x and y plus its width and height are outside of original box_mc boundaries. After you add child box_mc.width will be pic_mc.x + pic_mc.width and box_mc.height will be pic_mc.y + pic_mc.height.
    I suspect that because there is a border in the box, you expected objects to placed within the border. Border in the box IS NOT the box but ANOTHER object (child) inside the box. In other words, box is a container. After pic_mc is added - it will contain both border and pic_mc - not border containing pic_mc. You see the difference?

  • Controlling movie clip play order

    Good Day,
    I have a web site that opens with two movie clips. One (A)
    folds open some navigation menus, the other (B) opens some
    rectangles that hold content. I want "A" to play out then, once it
    is played, I want "B' to start. It sounds simple but I cannot get
    the right code. I need something I can use for other applications
    in other pages. I have this code so far; (naigation_mc = "A"
    page01_mc = "B")
    if (navigation_mc.play=true) {
    page01_mc.gotoAndStop("start");
    } else {
    page01_mc.gotoAndPlay("start");
    Perhaps there needs to be more code to controll this?

    The most likely cause for you problem lies in the scope of
    "this" in your case.
    While traitional flash5 style buttons would have the imeline
    in which they reside (e. g. the main timeline) as scope and a
    comand like
    on (release){
    stop();
    wouls stop he playhead of the main timeline.
    Where as the more modern form of attaching code to a button
    and the explicit use of
    this handles buttons like movieClips so that a command like:
    myButton.onRelease = function(){
    this.stop();
    will try to stop the buttons (= movieclips) own timeline.
    I hope that helps
    [This fact isn't stated clearly in the docs, but I at least
    asked Macromedia (back then) to add it at least to the live
    docs.]

  • Rotate a dynamilly created movie clip?

    I need to rotate this[PhotoMovieName]. But the registration
    point is the
    upper left corner. I want them to rotate on center.
    Is there a way to do this. Can I change the registration
    point with AS?
    PhotoArray = new
    Array("1.jpg","2.jpg","3.jpg","4.jpg","5.jpg");
    //trace(PhotoArray.length);
    for(i=0;i<PhotoArray.length;i++){
    trace(PhotoArray
    PhotoMovieName = "Photo"+i;
    var container:MovieClip =
    this.createEmptyMovieClip(PhotoMovieName,
    this.getNextHighestDepth());
    this[PhotoMovieName].loadMovie("Photo.swf");
    //this[PhotoMovieName].Photo_ldr._x=0;
    //this[PhotoMovieName].Photo_ldr._y=-50;
    this[PhotoMovieName]._rotation = 15*i;
    this[PhotoMovieName]._y = 200;
    this[PhotoMovieName]._x = 200;
    //this[PhotoMovieName].contentPath = PhotoArray;
    //this[PhotoMovieName].Photo_ldr.load();
    //trace(this[PhotoMovieName]._x+"----"+this[PhotoMovieName]._y);
    Thanks,
    Jason

    Jason,
    >I need to rotate this[PhotoMovieName]. But the
    registration point
    > is the upper left corner. I want them to rotate on
    center. Is there a
    > way to do this. Can I change the registration point with
    AS?
    ActionScript doesn't let you change an asset's registration
    point, but
    the workaround is pretty easy. In your case (ActionScript
    1.0/2.0) you'll
    create a containing clip first, then create another inside it
    -- as you're
    doing -- then offset the inner clip's midpoint to meet the
    registration
    point of the container.
    var container:MovieClip = this.createEmptyMovieClip(
    PhotoMovieName, this.getNextHighestDepth()
    So far, so good, right? Nothing has chnaged yet. Now,
    because you've
    created the variable container, and because the
    MovieClip.createEmptyMovieClip() method returns a reference
    to the newly
    created clip, may use the container variable in place of
    this[PhotoMovieName] -- because the reference to that clip is
    stored in
    container.
    container.loadMovie("Photo.swf");
    Again, that's functionally identical to the earlier version,
    this[PhotoMovieName].loadMovie("Photo.swf"); ... now, the
    important part at
    this point is to *wait* until Photo.swf has loaded. Until it
    does, you
    can't really continue, as you've done, with rotation, x, and
    y settings. If
    you go the route of loadMovie(), you basically have to set up
    a loop
    (setInterval(), say, or onEnterFrame) and repeatedly check
    the
    MovieClip.bytesLoaded() and bytesTotal() methods of your
    container clip
    until the loaded bytes meet the total. Here's some detail on
    that process
    http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded/
    ... Finally, you'll want to bump the loaded left by half its
    width and up by
    half its height -- then move the container to compensate. So,
    how do
    reference the loaded clip inside the container? Aha! Well,
    once Photo.swf
    is loaded, it's container effectively *is* the loaded asset.
    You'll need
    two containers, then. An outer and an inner.
    var outer:MovieClip = this.createEmptyMovieClip(
    PhotoMovieName, this.getNextHighestDepth();
    var inner:MovieClip = outer.createEmptyMovieClip("mcInner",
    0);
    inner.loadMovie("Photo.swf");
    outer.onEnterFrame = function():Void {
    if (inner.getBytesLoaded() >= inner.getBytesTotal()) {
    inner._x -= inner._width / 2;
    inner._y -= inner._width / 2;
    this._x += inner._width / 2;
    this._y += inner._width / 2;
    this._rotation = 45;
    delete this.onEnterFrame;
    A couple key things to note: again, the variable outer
    refers to
    whatever string is contained by the PhotoMovieName variable.
    This time,
    there's also an inner clip inside that one. The inner clip is
    basically
    taking the place of your original container. Once loading
    starts, a loop
    checks the loading SWF, as described in that blog link, and
    when the SWF has
    finished, inner is offset left and up, outer is offset right
    and down, and
    finally outer is rotated.
    David Stiller
    Adobe Community Expert
    Dev blog,
    http://www.quip.net/blog/
    "Luck is the residue of good design."

  • Trying to dynamically Rotate a Dynamically Created Movie Clip

    Hi As3 Gods...
    I want to rotate a movieClip that is created and animated by a function in the same Code window.
    var electron:MovieClip=new MovieClip
    createElectron(electron)
    electron.rotation=90 ------> I expect the whole animated MovieClip to rotate. nothing happens though.
    // I have a function that receives the electron and build / animates it
    function createElectron( receives the MovieClip + more parameters ):MovieClip
    { bunch of codes
    returns the MovieClip
    It is achievable if I create an external MovieClip through library, and put the createElectron codes inside that movieClip and export it to ActionScipt and then rotate it, but then i donno how to assign Parameters to an external function in the movieClip when i call the electron, i want to be able to tell the function what is the radius, speed, etc. I have never tried creating Classes, donno if it helps me here or not. I think i m failing to sort of WRAP the MOvieClip and the animation inside, so i can rotate the whole thing when returned.

    var electronsH:Array=new Array
    var electron:Sprite = new Sprite();
    buildElectronBeam(8,50,50)
    function buildElectronBeam(atom,repeatHorizontal,wide)
                 For loop{
                       var electron2:Sprite = new Sprite();
                      singleElectron(radius,4,electron2)  // here i send electron2 to be animated and built up in the called function
                      electron2.rotation=90 // This does rotate the electron but not the animation defined for it.
                       electronsH[h]= electron2
                       addChild(electronsH[h]) // shows that animation is still horizontal
    function singleElectron(radius,pixel,electron:Sprite)
    createPoint(pixel)
        function createPoint(radio:uint)
            electron.graphics.beginFill(0xFFFFFF,1)
            electron.graphics.drawRect(0,0,pixel,pixel)
            addChild(electron)
            electron.addEventListener(Event.ENTER_FRAME, movepixels) 
         function Animatepixels(e:Event)
         {   pixel starts to spin on a horizontal line}
    I think my problem is I dont know how to attach this animation to be part of the MovieClip so i Can rotate the whole thing. What i was trying to achieve here is to say flash "Consider whatever going on in this singleElectron function as my MovieClip" but as we both see, electron is the movieClip and animate function just performs something without being a part of MovieClip itself.

  • How to detect  collssion for random or Duplicated movie clips

    Hey guys .. i am back with set of query..till now .. key
    press movement a rocket (mc) is moving left right up down in a
    defined stage area. and i am able to generate some fire balls
    randomize falling from top. this is just i am duplicating the movie
    clip(fireball_mc) .... now i want incase or when the rocket (mc)
    touch the fire ball programm shold detect the collsion and generate
    a score board. well for this i have tried a script for two movie
    clips ... wchich is working but ..i don know or i m not gettng the
    logic how to detect the collission for duplicated movie clips...
    well i m just giving the script for oinly 2 movie clips
    coliding...can any one tell me how to do it with randmize or
    duplkicated mcs??
    for 2 movie clip ...
    _root.mc1.onEnterFrame = function() {
    if(this.hitTest(_root.egg)) {
    _root.result="Oh no..... we are dead";
    } else {
    _root.result="we are going fine";
    (this is happening ..but let me know how can i get the same
    result for ranndom mcs)
    hope someone can help me out ...
    i appriciate ur valuable time to read this..
    thanking you

    Hey thx for ur suggestion...but as i said m very much new to
    actionscript (more designer) so i don have much idea... most of the
    things i m doing for this game i m going through lots of references
    then i tried to understand te codes m implmenting them to my
    need..can u explain me little more about arrays u haves asked for
    loops u asked me to use the hittest function..please /.. i will be
    greatfull to u... thx

  • Nested Movie Clips

    hi,
    I recently downloaded a flash template that was built on AS2
    and have been trying to figure out how it works for a couple of
    weeks now (excuse my ignorance when it comes to AS). I have a
    question about nested Movie Clips. The way the template is
    constructed invovles a massive amount of nested movie clips and a
    large number of instances of each movie clip. The way i understand
    it is that if an instance of a movie clip is put on the stage and
    given an instance name, any modifications to that movie clip should
    be unique to that instance. However when i modify the colour of any
    of the movie clips i select, it changes the colour of all other
    instances.
    Am i missing something obvious here??
    Thanks in advance for your help
    Kind Regards
    Damien

    Yea. This particular template i am working with appears to
    change and manipulate colours dynamically as you said. Also it
    doesn't have all of the content (txt and images) within the actual
    flash document. They are all loaded dynamically through a txt
    document and external files (jpgs amoungst others) which makes it
    alot harder to edit since i dont fully understand the xml format
    they have in the txt document. As well as this, the template has
    no, and i mean NO documentation what so ever which makes it much
    more difficult to work through. But i guess i will keep pluggin
    away at it :)
    Thanks again for your help Ned
    Damien

  • Creating functions for movie-clips(serious problem)

    Hello,
    This is I think my third thread on these forums and in my
    previous threads I had always got some help.Well, now I have
    another serious problem, can you help me?
    I am unable to create a function that can control movie
    clips. Let me explain:-
    I have 10 movie clips on the stage and I have assigned them
    that whenever they crash to an object, they will go to a random
    position. Writing this code ten times for each movie clip would be
    very tedious, so, I thought about creating a function, but, it
    doesn't work. Here's the function, can you correct it?
    var object:movieClip;
    function position(object) {
    var testnum1:Number;
    testnum1 = random(290)+36;
    _root.object._y = -77.6;
    _root.object._x = testnum1;
    position(nameofmovieclip)
    PLEASE HELP IS REQUIRED!!!!
    Thanking All,
    Chinmaya

    Thanks for the reply,
    I tried that, it worked!
    But, now, I am encountering a really odd problem. This time
    I'll give you my full code.The problem is, that now when the object
    collides with another one, it changes its position according to the
    code but then after a while, it just passes through the object.
    Here's my code:-
    function position(object) {
    var testnum1:Number;
    testnum1 = random(290)+36;
    object._y = -77.6;
    object._x = testnum1;
    metal.onEnterFrame = function() {
    _root.metal._y += speednum;
    if (_root.metal.hitTest(_root.testline)) {
    position(_root.metal);
    speednum = random(6)+1;
    Can you help me out again,
    Thanks,
    Chinmaya
    P.S. I have tried to use the function like this:
    position(metal), but it doesn't work. And yes, I have already
    defines speednum somewhere before, so that isn't the
    problem.

Maybe you are looking for