A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 45

Thread: Cable

  1. #21
    Junior Member
    Join Date
    Jul 2012
    Posts
    22
    Is there a way to trace the cords of every particle of the cable?
    So if particle y is eg. 250 it should keep that y something like:

    Code:
    if particle._y == 250 {
          particle._y = 250;
          } else {
          //nothing xD
    }

  2. #22
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    hell no I didnt you're crazy lol he gave me an example file, I only modified it abit 0.0 that thing looked crazy
    yeah, it looks really crazy. Some math genius must've programmed that :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #23
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    yeah, dude there is but the only way to keep checking is by using onclipevent, but your file uses so much resources for some reason it will keep crashing.

  4. #24
    Junior Member
    Join Date
    Jul 2012
    Posts
    22
    It's okay its not needed it looks cool without floor too
    Thanks A LOT for the help,and soon as i'm finished with this project i will link it here so you can see what you did
    Just I need to buy new hosting
    Thanks again!

  5. #25
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    sweet

  6. #26
    Junior Member
    Join Date
    Jul 2012
    Posts
    22
    One more thing...i hope i'm not bothering you much with this :S
    How could i make that dragable plug movieclip make with rotation...
    eg. If i drag it up it rotates in mouse move direction so it rotates up if down it rotates to down...i hope you know what i mean :S xDDD

  7. #27
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    I suck at flash idk ask someone else or wait for a reply maybe nig13 will help

  8. #28
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I thought this was yours to solve ;P

    Remove all code from the plug (click on it, open actions panel, and delete everything). Open Actions Panel for Actions layer, and at the end, change this:

    Code:
    plug_mc.onRelease = plug_mc.onReleaseOutside = function(){
    	stopDrag();
    	if(this.hitTest(socket_mc)){
    		trace("Connected!");
    	} else {
    		plug_mc._x = 190
    		plug_mc._y = 190
    	}
    }
    to this:

    Actionscript Code:
    down = false;

    plug_mc.onPress = function(){
        startDrag(this, true);
        down = true;
    }

    plug_mc.onRelease = plug_mc.onReleaseOutside = function(){
        stopDrag();
        this._rotation = 0;
        down = false;
        if(this.hitTest(socket_mc)){
            trace("Connected!");
        } else {
            plug_mc._x = 190
            plug_mc._y = 190
        }
    }

    onMouseMove = function(){
        if(down){
            plug_mc._rotation = Math.atan2(b, a)*180/Math.PI;
            a = _root._xmouse - plug_mc._x;
            b = _root._ymouse - plug_mc._y;
        }
    }

    Not the smoothest, but at least it works :P
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  9. #29
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    no I solved it and it works fine, but if you use it alot flash tells you you are using to much resources and the thing lags out. It was because the onclipevent(load) uses to much resources, so eh thats all I can do, I dont think you fixed it he was asking for gravity

  10. #30
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I have no idea what he means, and it's confusing me even more now >.<"

    but, onClipEvent(load) shouldn't use anything, as it's fired only once. onClipEvent(enterFrame) on the other hand is always fired, so that one should use CPU, but maybe you used a for loop inside onClipEvent(load), an infinite loop which caused Flash to stop and ask to stop the script??
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  11. #31
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    actually onclip enterframe only fired for me once and onclip load continues the check for some reason.

    the dude means he wants gravity on the plug if you let it go it falls to the ground

    I got it working but with massive performance issues XD

  12. #32
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    oh, gravity O_O

    can I try :P?
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  13. #33
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    sure, I didnt save mine though because of the error but gravity is easy to add, try it and you will see flash will start to crash.

  14. #34
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Convert floor to movieclip and give it an instance name of, floor_mc

    On plug_mc:

    Actionscript Code:
    on(press){
        startDrag(this);
        gravity = false;
        grav = 0;
    }

    onClipEvent(load){
        gravity = true;
        grav = 0;
        speed = 0.9;
    }

    onClipEvent(enterFrame){
        this._y += grav;
        if(this.hitTest(_root.floor_mc)){
            grav = 0;
        } else {
            if(gravity){
                grav += speed;
            }
        }
    }

    and then on your Frame, change plug_mc.onRelase to this:

    Actionscript Code:
    plug_mc.onRelease = plug_mc.onReleaseOutside = function(){
        stopDrag();
        this.gravity = true;
        if(this.hitTest(socket_mc)){
            trace("Connected!");
        }
    }

    That kind of gravity??
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  15. #35
    Member Alloy Bacon's Avatar
    Join Date
    Apr 2011
    Posts
    1,089
    Jump up from the floor, do you see yourself still floating in the air or going back to set position no, you fall xD that kind of gravity.

  16. #36
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    I give up XD
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  17. #37
    Junior Member
    Join Date
    Jul 2012
    Posts
    22
    Forget about the gravity guys i told ya it looks awesome this way too
    So Nig what do you think about rotation i mentioned?
    That would be way better

  18. #38
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Already posted it on Post #28
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  19. #39
    Junior Member
    Join Date
    Jul 2012
    Posts
    22
    Yeah,i tried that it doesn't work :S

  20. #40
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    .... :/

    1. Click on the Plug movieclip, once (so that it is selected)
    2. Prses F9 to open actions panel, and it should say:

    Code:
    on(press){
    	startDrag(this);
    }
    
    
    
    onClipEvent(enterFrame){
    	if(this.hitTest(socket_mc)){
    		trace("Connected!");
    
    	}
    }
    3. Remove that code, so that there is NOTHING inside the Plug movieclip (in terms of actionscript)
    4. Click on the Frame of the layer named Actions
    5. Press F9 to view its codes
    6. Remove all the code, and replace it with this code:

    Actionscript Code:
    //cable_start_mc code
    np = 21;
    joints = [];

    elasticx = 2;
    elasticy = 2;

    flex = 1.1;
    D = 1.1;
    fa = 0.6;

    for(i=0;i<np;i++){
        sx = plug_mc._x + (cable_start_mc._x - plug_mc._x)/np*i;
        sy = plug_mc._y + (cable_start_mc._y - plug_mc._y)/np*i;
       
        joints[i] = {x:sx, y:sy, vx:0, vy:0};
    }

    function step(dt){
        //Kräfte sammeln
        for(i=0;i<np;i++){
            j = joints[i];
            j.ax = 0;
            j.ay = 0;
            //Erste Kraft vom vorhergehenden Element
            if(i<1){ //Am Anfang?
                j.ax += (plug_mc._x-j.x)*D;
                j.ay += (plug_mc._y-j.y)*D;
            }else{
                j.ax += (joints[i-1].x - j.x)*D;
                j.ay += (joints[i-1].y - j.y)*D;
            }
           
            //Zweite Kraft vom nachfolgenden Element
            if(i<np-1){
                j.ax += (joints[i+1].x - j.x)*D;
                j.ay += (joints[i+1].y - j.y)*D;
            }else{ //Am Ende
                j.ax += (cable_start_mc._x - j.x)*D;
                j.ay += (cable_start_mc._y - j.y)*D;
            }
            j.ay += flex;
        }

        //Integrieren
        for(i=0;i<np;i++){
            j = joints[i];
           
            j.vx += j.ax*dt;
            j.vy += j.ay*dt;
           
            j.vx *= fa;
            j.vy *= fa;
           
            j.x += j.vx*dt;
            j.y += j.vy*dt;
        }
    }
    this.onEnterFrame = function(){
        for(s=0;s<3;s++){
            step(1);
        }
       
        //Zeichnen
        this.clear();
        this.lineStyle(2);
        this.moveTo(plug_mc._x, plug_mc._y);
        for(i=0;i<np;i++){
            j = joints[i];
            this.lineTo(j.x, j.y);
        }
        this.lineTo(cable_start_mc._x, cable_start_mc._y);
       
    }
    down = false;

    plug_mc.onPress = function(){
        startDrag(this, true);
        down = true;
    }

    plug_mc.onRelease = plug_mc.onReleaseOutside = function(){
        stopDrag();
        this._rotation = 0;
        down = false;
        if(this.hitTest(socket_mc)){
            trace("Connected!");
        } else {
            plug_mc._x = 190
            plug_mc._y = 190
        }
    }

    onMouseMove = function(){
        if(down){
            plug_mc._rotation = Math.atan2(b, a)*180/Math.PI;
            a = _root._xmouse - plug_mc._x;
            b = _root._ymouse - plug_mc._y;
        }
    }

    If that doesn't work, then ...........
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

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