A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 25

Thread: Play the frame number from script

  1. #1
    Junior Member
    Join Date
    Dec 2016
    Posts
    12

    Play the frame number from script

    Hello.

    I have a MovieClip with 100 frames and I'm trying to get it to play the specific frames based on its acceleration values.

    Here's an image explaining what I'm aiming for. The MC with 100 frames should go and stay at the 50th frame. Depending on its movement from left or right, it should play the movieclip frames inside forward or backward.

    I'm a total noob so any help is appreciated.

    Attachment 75711

  2. #2
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Here's how it should look like when moving

    http://www.dreamincode.net/forums/up...1482001513.gif
    Attached Images Attached Images

  3. #3
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Unless the gif has a glitch when the slider is returning thats not possible because why would you slide it left and it slides but than you bring it back and it doesnt slide. If you make it move with code it will work but not with key frames

  4. #4
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Quote Originally Posted by Alloy Bacon View Post
    Unless the gif has a glitch when the slider is returning thats not possible because why would you slide it left and it slides but than you bring it back and it doesnt slide. If you make it move with code it will work but not with key frames
    onClipEvent (enterFrame) {
    var fNum:Number = 50;
    gotoAndStop(fNum);
    }

    Normally the code above works if you manually enter a number but I need it to read it from the position value of another object to create the swing effect.

    So it should look like ;

    onClipEvent (enterFrame) {
    var fNum:Number = _root.Target._x;
    gotoAndStop(fNum);
    }

    but for some reason it doesn't work.

  5. #5
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    onClipEvent (enterFrame) {
    var fNum:Number = _root.Target._x;
    gotoAndStop(fNum);
    }

    I would not declare variable names at 30fps i would declare it once outside the enterframe like this:

    var fNum:Number = _root.Target._x;
    onClipEvent (enterFrame) {
    fNum=_root.Target._x;
    this.gotoAndStop(fNum);
    }


    or no var is better:

    onClipEvent (enterFrame) {
    this.gotoAndStop(_root.Target._x);
    }




    dont let your mc exceed 100px
    Last edited by AS3.0; 12-20-2016 at 12:50 PM.

  6. #6

  7. #7
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Why are you giving him abort the script codes Alloy, he wants help not flash not responding.

    Seems you have since removed it.

    Maybe attach your fla that you have made Alloy, bbut it would also help to see the fla that the poster has created.
    Last edited by fruitbeard; 12-20-2016 at 12:55 PM.

  8. #8
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Alloy it would be
    PHP Code:
    onClipEvent (load)
    {
        var 
    fNum:Number _root.Target._x;
    }

    onClipEvent (enterFrame)
    {
        
    fNum _root.Target._x;
        
    this.gotoAndStop(fNum);

    if you were declaring the variable outside of the movieclip then it would be referenced using _root.fNum or _parent.fNum

  9. #9
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Thanks alot guys.

    I figured out that the problem was that the _x value had fractions and that was whats messing up the script. I added a 'math:round' before '_root.Target._x' and it worked like a charm. I got the first part working where the frame it plays change depending on the _x position of another object. Now I wanna calculate the _x difference of the current and previous frames of that object and tell the MC which frame to play.

  10. #10
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Quote Originally Posted by fruitbeard View Post
    Hi,

    Alloy it would be
    PHP Code:
    onClipEvent (load)
    {
        var 
    fNum:Number _root.Target._x;
    }

    onClipEvent (enterFrame)
    {
        
    fNum _root.Target._x;
        
    this.gotoAndStop(fNum);

    if you were declaring the variable outside of the movieclip then it would be referenced using _root.fNum or _parent.fNum
    Thanks for the help I think I've figured it out with the code above. I got something else to do for the swing now. Would you mind helping me convert a few AS1 scripts into AS2 ?

  11. #11
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    I'm attaching the file below
    Attached Files Attached Files
    Last edited by GauFra; 12-21-2016 at 01:33 PM.

  12. #12
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Here's the AS1 flash file
    Attached Files Attached Files

  13. #13
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    as1 should already work in a as2 environment if im not wrong

  14. #14
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Quote Originally Posted by Alloy Bacon View Post
    as1 should already work in a as2 environment if im not wrong
    Switching from Flash 5(AS1) to Flash 8(AS2) breaks the script and nothing works.

  15. #15
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    actions for as1 & as2 are written for the same environment on flash cs6, your tween ran fine in cs6

    maybe you are asking for it to be ported to actionscript compiler 2.0 which is actionscript 3.0?
    Last edited by AS3.0; 12-22-2016 at 11:14 PM.

  16. #16
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Quote Originally Posted by Alloy Bacon View Post
    actions for as1 & as2 are written for the same environment on flash cs6, your tween ran fine in cs6

    maybe you are asking for it to be ported to actionscript compiler 2.0 which is actionscript 3.0?
    The flash was set to be published for flash 5 with AS1. When I changed it to Flash 8 and AS2 it didn't work. It didn't show any errors but the spring effect wasn't working. I just need this script to run in AS2.

  17. #17
    Junior Member
    Join Date
    Dec 2016
    Posts
    12
    Quote Originally Posted by Alloy Bacon View Post
    actions for as1 & as2 are written for the same environment on flash cs6, your tween ran fine in cs6

    maybe you are asking for it to be ported to actionscript compiler 2.0 which is actionscript 3.0?
    Did the flash work on your file ?

  18. #18
    Member
    Join Date
    Oct 2016
    Posts
    54
    maybe he not know answer, maybe he never download it, maybe he not able do it, maybe he going to surprise.

  19. #19
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    dezoid go learn at english kit and dont come back until you do

  20. #20
    Member
    Join Date
    Oct 2016
    Posts
    54
    merre chrissmas alloys, i jus wonder if you have fixed the guy, or maybe you no downloaded file or perhap you not able to help because you can not do it.
    honest is only answer alloy

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