A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: pull-string in AS3?

  1. #1
    Junior Member
    Join Date
    Oct 2008
    Posts
    10

    pull-string in AS3?

    What I want to create is a lightbulb, with a pull-string next to it. When you pull the string, the lightbulb turns on, and when you let go, the string bounces up and swings around, causing the lightbulb to swing slightly as well.

    I tried to do this with prefabbed animations, but it just doesn't look right. I know i have to code it so a movie clip of a single dot spawns several instances of itself, and I can do that... but then I get lost.

    I've looked everywhere for tutorials/references/or anything, but I'm coming up empty.

    Could anyone help me?

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    tweenlite will probably let you animate the bulb on the x and the string on the y...checkout ease:Bounce:EaseIn
    ~calmchess~

  3. #3
    Junior Member
    Join Date
    Oct 2008
    Posts
    10
    what about the string bending and curving? :/

    it seems that's more suited for static objects

  4. #4
    Untitled-1.fla strille's Avatar
    Join Date
    Mar 2001
    Location
    Sweden
    Posts
    1,626
    You could implement a spring system to do this. A spring system is basically a simple physics model suitable for simulating ropes, chains, cloth etc. There are tons of examples online describing how they work and how to implement one.

    The simplest solution is to use a physics engine, such as http://www.fisixengine.com. Here's an demo, which contains something similar to what you describe: http://www.fisixengine.com/demos/mona1.html

  5. #5

    easing and springing

    What you are looking for is easing and springing. It is a bit of an advanced animation concept. But once you do it , it becomes second nature.

    PHP Code:
    //Simple spring, long form:
    var ax:Number = (targetX sprite.x) * spring;
    var 
    ay:Number = (targetY sprite.y) * spring;
    vx += ax;
    vy += ay;
    vx *= friction;
    vy *= friction;
    sprite.+= vx;
    sprite.+= vy;

    //Simple spring, abbreviated form:
    vx += (targetX sprite.x) * spring;
    vy += (targetY sprite.y) * spring;
    vx *= friction;
    vy *= friction;
    sprite.+= vx;
    sprite.+= vy;

    //Simple spring, short form:
    vx += (targetX sprite.x) * spring;
    vy += (targetY sprite.y) * spring;
    sprite.+= (vx *= friction);
    sprite.+= (vy *= friction); 
    you would want to connect these springs together to make a 'string' as in thread. use the code to draw lines to each other.

    PHP Code:
    graphics.clear();
    graphics.lineStyle(1);
    graphics.moveTo(ball0.xball0.y);
    graphics.lineTo(ball1.xball1.y); 

    www.onenterflash.com | Learn Free

  6. #6
    Junior Member
    Join Date
    Oct 2008
    Posts
    10
    Thank you! xD

    This is exactly what I needed!

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