A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Inertia

  1. #1
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611

    Inertia

    Anyone can teach me the effects on inertia.Like fading an mc,scaling an mc>change the w,h.change position,...

    Since I post this in the newbie section.Can someone explain me as simple as possible or drop me a .fla file(zipped).Big thx in advance.

    Grtzz,

    Modulater

  2. #2
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488

  3. #3
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    Can you explain me a liddle more.

    This is the object or frame action made for the new mc?
    onClipEvent (load) {
    delay = 3;
    _root:locationY = 200;
    }

    When I make a new mc,place the code in a frame action.I get a somthing wrong with script error.

    This is the action given to a button placed in the root?

    onClipEvent (enterFrame) {
    locationDif = _root:locationY-_y;
    _y += locationDif/delay;
    }

    Same error here.

    You can explain me more or attach me a zipped .fla file.I really like to know this effects.Pleace help.Thx

  4. #4
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    It should be an event attached to the clip itself and not within a frame

    What this code does it in the load event set a position to movie to (_root.locationY) if you have more than one clip you want to move to you might want to make this variable inside the movie clip (locationY = 200) instead of on root.

    the variable delay controls the easing for the object. a larger value creates a smoother effect, a smaller value moves the object rapidly towards the point (try a value between 0 and 1 eg 0.8 to get a weird oscillating effect )

    the enterFrame loop calculates a step towards positionY by finding the difference between the clips current y position and the positionY variable and dividing this difference by delay.

    try,

  5. #5
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    Ok I made an mc,placed it on scene,gave the mc the code listed above.The effect I got was the square moved downwords.
    So If >y is set to 200 this moves the mc 200 pixels?How can I give the effect to an mc hitting a button.Button a> moves 200 pixels.Button b >moves the mc 400 pixels.This I wanne know.
    Also how rescale the mc hitting a button with this easing effect.

  6. #6
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    The value set for locationY is the final y position you want the clip to end up at.
    Here's an example file that randomizes the scale and position of the clip.
    Attached Files Attached Files

  7. #7
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Could this be added to a frame action so you could control where and when and what size and position the box appears? Or to a button?

    I played with your code, and added another onmousedown after the onenterframe frame event, and it bypassed the first mousedown and went to the last. Not quite sure why it did that, or even why it worked at all.

    Code:
    onClipEvent(load) {
    	var easing = 5;
    	var xFinal = 500;
    	var yFinal = 400;
    	var xScaleFinal = 200;
    	var yScaleFinal = 200;
    }
    onClipEvent(mouseDown) {
    	var xFinal = 300;
    	var yFinal = 200;
    	var xScaleFinal = 200;
    	var yScaleFinal = 200;
    }
    onClipEvent(enterFrame) {
    	this._x += (xFinal - this._x) / easing;
    	this._y += (yFinal - this._y) / easing;
    	this._xscale += (xScaleFinal - this._xscale) / easing;
    	this._yscale += (yScaleFinal - this._yscale) / easing;
    
    }
    
    onClipEvent(mouseDown) {
    	var xFinal = 400;
    	var yFinal = 200;
    	var xScaleFinal = 400;
    	var yScaleFinal = 300;
    }

  8. #8
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Hi,

    You could move code to a button to first position the clip and then set its target position/scale/whatever other property you want to change.

    maybe try something like this,

    Code:
    onClipEvent(load) {
    	var easing = 5;
    	var xFinal = this._x;
    	var yFinal = this._y;
    	var xScaleFinal = this._xscale;
    	var yScaleFinal = this._yscale;
    }
    // and then the same enterFrame event as before
    this sets the values of the target variables to be the same as the current state of the clip. by doing this you don't see any tweening until the button or frame event sets up the new values.

    a button could then be scripted,

    Code:
    on (press) {
            instanceNameOfClip._x = something;
            instanceNameOfClip._y = something;
            instanceNameOfClip._xscale = something;
            instanceNameOfClip._yscale = something;
    
            instanceNameOfClip.xFinal = anotherValue;
            instanceNameOfClip.yFinal = anotherValue;
            instanceNameOfClip.xScaleFinal = anotherValue;
            instanceNameOfClip.yScaleFinal = anotherValue;
    }
    now when the button is pressed you can position the clip and send it new values for xFinal, yFinal etc... this should cause the tweening to start.

    Hope it helps

  9. #9
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Mr. Bert, as always, you are the MAN...

    Modified it a bit. I found that removing the top half of the button code made it work perfect, moving to the new location from the last location on press. Something like this:

    Code:
    on (press) {
            box.xFinal = 40;
            box.yFinal = 125;
            box.xScaleFinal = 200;
            box.yScaleFinal = 150;
    }
    Otherwise you had to code in the last position and size. So I have tried this code on three buttons, and it works beautifully. I appreciate the effort, I've been working nights on finding a way to do this, and got nowhere. I'm missing something essential in my thinking about code. Darn it...

  10. #10
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Glad to help

  11. #11
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    I can't seem to download the file in a proper way
    Can you zip the file for me.I'm on a mac and this is the only way to download fla file.I tryed to make this effect but it just did not work for me.Still a newbie you know.So I attached what I did.Can you have a look at it.If I got things wright know the code works with a scale factor.Can't this be done with a change weight,height?I really would appreciate you looked into my file.I'm really stuck in this matter. THX

    Ps.this script only works in MX or does it also work in flash5
    Cab you drop a fade effect also in 'my not working file'
    Attached Files Attached Files

  12. #12
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    This code I gave to the mc:

    onClipEvent(load) {
    var easing = 0.7;
    var xFinal = this._x;
    var yFinal = this._y;
    var xScaleFinal = this._xscale;
    var yScaleFinal = this._yscale;
    }
    onClipEvent(enterFrame) {
    this._x += (xFinal - this._x) / easing;
    this._y += (yFinal - this._y) / easing;
    this._xscale += (xScaleFinal - this._xscale) / easing;
    this._yscale += (yScaleFinal - this._yscale) / easing;
    }

    This code I gave to the button:
    on (press) {
    box.xFinal = 40;
    box.yFinal = 125;
    box.xScaleFinal = 200;
    box.yScaleFinal = 150;
    }

  13. #13
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    Does that do what you're wanting it to?

  14. #14
    Senior Member
    Join Date
    Oct 2002
    Location
    belgium
    Posts
    611
    It works perfect now.I removed the fscommand and everything seems to work perfect now.Strange,but it works now.Could you add me also code to fade the mc,or make it invisible.

    How can you control the mc.Like when hit>the mc first moves,then scales,then fades,the is invisble.is this possible and how acheave that.

    Grtzz

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