all groups > flash (macromedia) > october 2007 >
You're in the

flash (macromedia)

group:

Can this be done?



Can this be done? f_l_a_s_h
10/22/2007 9:53:20 PM
flash (macromedia): Is it possible to make a stem grow from the ground, then a flower once the stem
is a certain height. Then, the flower would be "attracted" to the mouse once
it gets close enough. And finnaly the flower would be clickable. I'm just not
sure where to start? Please help a newbie :)
Re: Can this be done? clbeech
10/23/2007 12:41:34 AM
yes, absolutely, this is the kind of thing that Flash was meant for. You need
to start by maiking an animation sequence of the stem growing to height, then
one of the flowering. both of these things should be MovieClips, then add some
scripts to 'attract' it toward the mouse, but you may need to produce some
other animations here with the 'stem' to make it look like it's bending. You
could do this with the drawing API but it's going to get a little too complex.
(hmmm... working on this)

But really what you should do first, is start reading the Help manual and
'getting started with Flash' and do a few tutorials to start getting a basic
understanding of how this program works.
Re: Can this be done? f_l_a_s_h
10/23/2007 3:51:42 PM
Awesome. Thanks for the reply... I have done "some" flash work and action
script work... we'll copy and pasting anyways. Here's a bit that I found that
could help the attraction part...

onClipEvent(enterFrame){ //make it so it runs every frame
this._x -= (this._x-_root._xmouse)/20; //making it move smoothly towards the
_xmouse, adjust the 20 for different speeds
this._y -= (this._y-_root._ymouse)/20; //same as the line above, except for _y
}

So I guess what I'd like to try is that as the mouse gets within 100 pixles of
a movie clip, the movie clip would spring to the mouse location and stick with
it. It would also stick to the stem. When the mouse pulls the movie clip more
then 200 pixels from it's original location, it would let go and elastically
bounce back into it's original location...

I understand that I would have to make the flower "grow" using tweening I
guess.

The problem is, I need the "Stem" to spring up... Man this is going to be a
lot I think...
Re: Can this be done? clbeech
10/23/2007 6:10:43 PM
Cool, you're thoughts here are a little easier to implement really, your on the
right track, I would consider writing these event a little differently, but
play around with it for awhile, it's good practice :) To get this to happen
when the mouse is within a certain 'bounds' there are several ways to go about
it, but the main principle is to use 'conditions' that is, a statment that
compares a series of critiera that returns a 'true' or 'false' result.

I was thinking that what you wanted to do was make the flower 'bend' toward
the mouse, which is a little tougher, but far from impossible. So I'll write
two code snippits below as examples, the first will be using conditions as
you've described, and the second is a little experiment for the 'bending' idea.
To use the first, place it on the timeline, first frame with a 'flower_mc'
instance on the Stage. To use the second, just paste it into the first frame
of a new doc, it doesn't need anything else on the Stage at this point.


//FIRST EXAMPLE - flower_mc positioned at 200, 200 (x,y);

stop();
import mx.transitions.Tween;
import mx.transitions.easing.Strong;

var home=true;

onEnterFrame = function() {
if(home) {
//if the flower_mc IS at the 'home' position, check to see if the cursor
is within the bounds

if(_xmouse>100 && _xmouse<300) {
//if WITHIN the bounds limit AND the flower_mc is at the 'home' position
var fX = new Tween(flower_mc, '_x', Strong.easeOut, flower_mc._x,
_xmouse, 10, false);
var fY = new Tween(flower_mc, '_y', Strong.easeOut, flower_mc._y,
_ymouse, 10, false);
fX.onMotionFinished = function() {
home=false; //wait until the tween is complete to set this, to keep it
from 'snapping' to the cursor
}
}

}else{
//if the flower_mc IS NOT at the 'home' position

if(_xmouse<50 || _xmouse>350) {
//if OUTSIDE the bounds limit move the flower_mc back to the 'home'
position
home=true; //reset this immediately to keep fromreverting back to moving
with the cursor or restarting the Tween
var fX2 = new Tween(flower_mc, '_x', Strong.easeOut, flower_mc._x, 200,
10, false);
var fY2 = new Tween(flower_mc, '_y', Strong.easeOut, flower_mc._y, 200,
10, false);
}else{
//if NOT outside the bounds limit move the flower_mc with the cursor
flower_mc._x = _xmouse;
flower_mc._y = _ymouse;
}
}
}


//SECOND EXAMPLE OF BEND - nothing on the stage
stop();

stem = this.createEmptyMovieClip('stem',0);
stem._x = stem._y = 200;
stem.lineStyle(4, 0x009900);
stem.moveTo(0, 0);

var g=0;

function grow() {
onEnterFrame = function() {
stem.lineTo(0, g);
if(g>-40) {
g-=1;
}else{
delete onEnterFrame;
bend();
}
}
}
grow();

function bend() {
onEnterFrame = function() {
stem.clear();
stem.lineStyle(4, 0x009900);
if(_xmouse<stem._x) {
cX = (stem._x-_xmouse)/10;
aX = 0-cX;
aY = (0-cX/2)+40;
}else{
cX = 0-(_xmouse-stem._x)/10;
aX = 0-cX;
aY = (cX/2)+40;
}
stem.curveTo(cX, -20, aX, -aY);
}
}
Re: Can this be done? f_l_a_s_h
10/23/2007 6:51:22 PM
Wow... I really appreciate this help. And yes, I would like the stem to
bend... (though I never thought it would be possible). You must admit, if it
wasn't for people like you, people like me would never get to a point were we
would be able and willing to help others like me. I'll research this tonight
and hopefully post a sample of what I've created soon. Thanks again.
AddThis Social Bookmark Button