A Flash Developer Resource Site

Results 1 to 12 of 12

Thread: Rotating mc

Hybrid View

  1. #1
    Junior Member
    Join Date
    Feb 2007
    Posts
    11

    Rotating mc

    Hy guys me again. Have another problem which I cant solve. The problem is that i would like to rotate my mc on the press of a button. But i cant. The transition works the way i want it to but the problem is that it starts in the end ad finishes at the begging. if t change the IN to OUT works perfectly but disappears on the end or jumps to the beginning.

    Can anyone help me. I didn't put any code in because noting works

    my_mc.rotation = 90; works but there is no animation in between 0 and 90 degrees.

    tnx in advance

    GP

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    PHP Code:
    var myTimer:Timer = new Timer(1,1000);
    myTimer.start ();
    myTimer.addEventListener (TimerEvent.TIMERtimerHandler);
    function 
    timerHandler (e:TimerEvent):void
    {
        
    my_mc.rotation += 1;
        if (
    my_mc.rotation >=90)
        {
            
    e.currentTarget.removeEventListener (TimerEvent.TIMERtimerHandler);
        }

    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Junior Member
    Join Date
    Feb 2007
    Posts
    11
    tnx allot. Work's perfectly.

    I just want to know something else. How can i call mc thats inside another mc. Because if fist mc is called stagee and the other one is called portfolio the portfolio.addEventListener.... doesn't work.

    1120: Access of undefined property portfolio.

  4. #4
    Junior Member
    Join Date
    Jan 2008
    Location
    Somerset, UK
    Posts
    25
    Quite simply,

    stagee.portfolio.addEventListener

  5. #5
    Junior Member
    Join Date
    Feb 2007
    Posts
    11
    I tried that ended whit

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at flashstran_fla::MainTimeline/flashstran_fla::frame1()

    Here is the whole code if it helps.

    Code:
    stagee.portfolio.addEventListener(MouseEvent.CLICK, click_port);
    
    function click_port(event:MouseEvent): void {
    	
    var myTimer:Timer = new Timer( 10,1000);
    myTimer.start ();
    myTimer.addEventListener (TimerEvent.TIMER, timerHandler);
    function timerHandler (e:TimerEvent):void
    {
        stagee.rotation += 2;
    
        if (stagee.rotation >=90)
        {
            e.currentTarget.removeEventListener (TimerEvent.TIMER, timerHandler);
        }
    	}
    var myTimer2:Timer = new Timer( 10,1000);
    myTimer2.start ();
    myTimer2.addEventListener (TimerEvent.TIMER, timerHandler2);
    function timerHandler2 (e2:TimerEvent):void
    {
        stagee.y += 2;
    	
        if (stagee.y >=290)
        {
            e2.currentTarget.removeEventListener (TimerEvent.TIMER, timerHandler2);
        }
    	}
    	
    }

  6. #6
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Do you have the movie clip ( stagee ) initialized on the same frame number as the code is ? Because if your movie clip "will come in play" only after, let's say, 10 frames ( or even 1 frame ) then the code won't see it, it won't be aware of it's existence and it will consider it "null" ( inexistent ).



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  7. #7
    Junior Member
    Join Date
    Feb 2007
    Posts
    11
    thats true. The portfolio mc thats inside stagee is on frame 40 or something. So what to do? Is it possible to do it whiteout moving the mc on the beginning and give it play(); on some point?

  8. #8
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Not really, you must move the mc to the beginning of the animation. Have it "hidden" for the time of the first 40 frames and make it visible once it reaches frame 40. OR, you could paste your code onto frame 40 where your mc is located... Can't really do anything more about it, or move the code to the mc or vice-versa.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  9. #9
    Junior Member
    Join Date
    Feb 2007
    Posts
    11
    tnx. Basically i just put the code on the frame where the button is and removed all the mc name from from the script:

    Like this. And it works
    Code:
    portfolio.addEventListener(MouseEvent.CLICK, click_port);
    
    function click_port(event:MouseEvent): void {
    	
    var myTimer:Timer = new Timer( 10,1000);
    myTimer.start ();
    myTimer.addEventListener (TimerEvent.TIMER, timerHandler);
    function timerHandler (e:TimerEvent):void
    {
        rotation += 2;
    
        if (rotation >=90)
        {
            e.currentTarget.removeEventListener (TimerEvent.TIMER, timerHandler);
        }
    	}
    var myTimer2:Timer = new Timer( 10,1000);
    myTimer2.start ();
    myTimer2.addEventListener (TimerEvent.TIMER, timerHandler2);
    function timerHandler2 (e2:TimerEvent):void
    {
        y += 2;
    	
        if (y >=290)
        {
            e2.currentTarget.removeEventListener (TimerEvent.TIMER, timerHandler2);
        }
    	}
    	
    }

  10. #10
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Great ! Good luck with your project.

    PS: since you did place the code on the same frame as the mc, it would be still ok to have the mc's name there. It might get messy once it gets more complex. That's just a friendly hint.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


  11. #11
    Junior Member
    Join Date
    Feb 2007
    Posts
    11
    tnx for advice but there is another problem with that. If i put the name of the mc in it wont work. Probably because I'm calling the mc from inside of him.
    So if i put his name I get:

    1120: Access of undefined property stagee.

  12. #12
    trace("AKA: Biro Barna");
    Join Date
    Oct 2007
    Location
    RO.Timişoara
    Posts
    1,403
    Aaaa, well if you are calling the mc from inside of him then it won't work by putting the name. It's not really good to have code inside objects ( only if that's really your last and only option ). It's more efficient and organized to control everything from the main timeline.

    You placed your code inside it and it worked, just leave it the way it was. Just keep in mind that putting code inside objects is not a good practice.

    Have fun.



    | Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
    WebLog: http://blog.wisebisoft.com/ |
    | Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
    |
    Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
    | By perseverance the snail reached the ark. |


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center