This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Flash Site Design > May 2005 > controlling movieclips with conditionals





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author controlling movieclips with conditionals
moebetta

2005-05-05, 11:17 pm

I am building a photo gallery which contains thumbnails.
On ROLLOVER, the frame(the frame I'm referring to is a .png file I made and
imported in to the movies library. The actual .jpg will sit on top of
this)around the thumbnail glows momentarily and then goes back to normal.
On PRESS, the frame around the thumbnail glows and continues to glow.

That much Ive been able to do succesfully. The problem is if the thumbnail
has been selected(pressed), then I would like it to continue to glow even if
the cursor rolls over it again. Currently, if it has been selected it glows and
will continue to, untill it is rolled over again. At which point it executes
the rollover behavior (glow a few seconds the goes back to normal). It should
only go back to normal when another thumbnail is pressed.

The basic layout of the flash movie is this:
Main timeline has a layer on it called "thumbnails"
On the "thumbnails" layer is a movieclip instance called "thumbnail_holder_mc"
Inside this movieclip are a number of layers. On each of these layers there is
an intance of a movieclip called "thumbnail_animation" (ie. On layer 1 there is
"thumbnail_anim1_mc", on layer 2 there is "thumbnail_anim2_mc" etc...)
Inside the movieclip "thumbnail_animation" are the tweens and the .png I'm
using as the "frame" for the thumbnails. The timeline frames inside
"thumbnail_animation" are labeled to identify where the effect starts and stops
and so on.

What I've done is assigned the same ON ROLLOVER and ON PRESS events to each of
the "thumbnail_animation" movieclip instances on each layer. Using this:

on (rollOver) {

//Movieclip GotoAndPlay Behavior
this.gotoAndPlay("glow_rollover");
//End Behavior

}
on (press) {

//Movieclip GotoAndPlay Behavior
this.gotoAndPlay("glow_press");
//End Behavior

}

What I suspect I need is some sort of "if,then" conditional statement so that
if one instance of the "thumbnail_animation" movieclip (ie
"thumbnail_anim1_mc") has been pressed it will continue to glow even if it is
rolled over again. It should only stop when another instance of
"thumbnail_animation" (ie "thumbnail_anim2_mc")is pressed.

I've tried to find out how to do this by reading the help files and message
boards but I am too much of a newbie to actionscript , and programming in
general to figure it out. If any one can help me, I would greatly appreciate
it. Thanks in advance to everyone!!!
P.S. If this is confusing or vague just let me know and I will try and clarify.

moebetta

2005-05-06, 7:20 pm

Is there anyone who might be able to assist me?
tralfaz

2005-05-07, 4:18 am

"moebetta" <webforumsuser@macromedia.com> wrote in message
news:d5ee48$7vm$1@forums.macromedia.com...
>
> What I've done is assigned the same ON ROLLOVER and ON PRESS events
> to each of
> the "thumbnail_animation" movieclip instances on each layer. Using
> this:
>
> on (rollOver) {
>
> //Movieclip GotoAndPlay Behavior
> this.gotoAndPlay("glow_rollover");
> //End Behavior
>
> }
> on (press) {
>
> //Movieclip GotoAndPlay Behavior
> this.gotoAndPlay("glow_press");
> //End Behavior



Sometimes it is better not to control objects directly, but rather to
set conditional flags that will be watched by the objects. Something
like this...
on (rollOver) {
_root.glowing = true;
}


on (rollOut) {
_root.glowing = false;
}

on (press) {
_root.pressing = true;
}

on (release) {
_root.pressing = false;
}


Then the animated clips watch the flags to decide what to do..

myAnimatedClip.onEnterFrame = function()
{
if(_root.glowing)
doSomeGlowingThings();

if(_root.pressing)
doSomePressingThings();
}

Setting conditional flags is a good way to make movieclips change
states gradually instead of suddenly. A good example is menus that
roll out when you mouse over them. When you move the mouse away,
instead of a sudden gotoAndStop(1) you can set menu.lookAtMe = false,
and menu can see that condition and start running itself backwards to
fold the menu back up.
tralfaz




moebetta

2005-05-07, 7:19 pm

tralfaz,
Thank you for the reply!!!
I came upon it last night and tried to build on it. However I could not get it
to work. I completely understand the principal behind it, there are just a few
things I'm not too sure about. I'm afaraid this is due to my inexpereince with
programming.
I understand what the first portion of that example you gave does and if I'm
not mistaken it should be attached to the movieclip instance itself.

As for the second part:
"myAnimatedClip.onEnterFrame = function()
{
if(_root.glowing)
doSomeGlowingThings();

if(_root.pressing)
doSomePressingThings();
}"

If I'm not mistaken should go something like this:

"1_mc.onEnterFrame = function()
{
if(_root.glowing)
goToAndPlay(60);

if(_root.pressing)
goToAndPlay(15);
}

I'm not quite sure where this portion of script should be put. I'm thinking it
should be put on the first frame of the movieclip instance. Is this right? I
also don't know what to do with the "function ()" part. I tried putting in
"false()", "true()", "glowing()"
".glowing" just to make something happen but none of it worked. I looked up
functions in the help file but something is not sinking in. I know I'm on the
right track because when I mouse over the movieclip the curser turns to a hand
at least! If you could just help me out a wee bit more I think I'lll have it
nailed down. Untill then I'll continue to work on it myself.
Thanks againfunction

moebetta

2005-05-07, 7:19 pm

Ok, upon further study and ripping my hair out(in clumps mind you).
I put together the following...

-------------------assigned to movieclip"1_mc" which is an instance of
"thumb_anim_mc"------------------
on (rollOver) {
_root.thumbnail_holder_mc.thumb_anim_mc.glowing = true;
}


on (rollOut) {
_root.thumbnail_holder_mc.thumb_anim_mc.glowing = false;
}

on (press) {
_root.thumbnail_holder_mc.thumb_anim_mc.pressing = true;
}

on (release) {
_root.thumbnail_holder_mc.thumb_anim_mc.pressing = false;
}

----------assigned to 1st Frame of the
movieclip"thumb_anim_mc---------------------

thumb_anim_mc.onEnterFrame = play()
{
if(_root.thumbnail_holder_mc.thumb_anim_mc.glowing)
doSomeGlowingThings(60);

if(_root.thumbnail_holder_mc.thumb_anim_mc.pressing)
gotAndPlay(15);
}

I took what rafalz gave me and decided to try and use absolute paths. I think
i also figured out what to do with that function in the second part. I'm still
stuck in the same boat because nothing happens. I've tried all manner of
variations and tweaks but I just have not been able to get it to work yet.

If you need a refresher on the layout of my movie, here it is:
Main timeline has a layer on it called "thumbnails"
On the "thumbnails" layer is a movieclip instance called "thumbnail_holder_mc"
Inside this movieclip are a number of layers. On each of these layers there is
an intance of a movieclip called "thumbnail_anim_mc" (ie. On layer 1 there is
"1_mc", on layer 2 there is "2_mc" etc...)
Inside the movieclip "thumbnail_anim_mc" are the tweens and the .png I'm using
as the "frame" for the thumbnails. The timeline frames inside
"thumbnail_animation" are labeled to identify where the effect starts and stops
and so on.

tralfaz

2005-05-08, 4:15 am

"moebetta" <webforumsuser@macromedia.com> wrote in message
news:d5j7u8$qel$1@forums.macromedia.com...
> Ok, upon further study and ripping my hair out(in clumps mind you).
> I put together the following...
>
> -------------------assigned to movieclip"1_mc" which is an instance
> of
> "thumb_anim_mc"------------------
> on (rollOver) {
> _root.thumbnail_holder_mc.thumb_anim_mc.glowing = true;
> }


It's all pretty confusing what you want to do moebetta, but one thing
I see is that you have invalid instance names of 1_mc, 2_mc, 3_mc
Don't start an instance name with a number like that. Try mc_1, mc_2,
mc_3

Also, if mc_1, mc_2, mc_3 are instance names of the library object
"thumb_anim_mc", you would not use that library name "thumb_anim_mc"
in your code anywhere.. refer to the objects made from it with their
instance names like "mc_1" _root.thumbnail_holder_mc.mc_1.glowing =
true;

I couldn't really make out what you want your clips to do. Maybe if I
show you an example of controlling movieclips with conditional flags
you might see how you want to do your file. I made a little test file
for you to look at. MX sourcecode is there. (not MX2004, not AS2) I
put lots of comments inside.
My coding style is to put all AS code in one place.. not attached or
inside objects. All the code is in frame 1 of the main timeline.

Hope it helps ya somehow.
http://members.cox.net/4my5cats/testflags.htm
tralfaz



moebetta

2005-05-09, 4:15 am

Tralfaz,

Just wanted to thank you for taking the time to help me out. I really
appreciate it. I took a look at the example. I know it's better to put all the
actions for your movie into one place. Typically, an actions layer on the root
timeline. It seems to me that doing it that way requires more skill with
actionscript than I have right now. I'll get a book in about a week. You know
anygood ones on actionscript by chance? In the meantime I'll have to make the
effect a bit more simple and get on with the rest of the gallery. I'll also be
taking a really good look at the actionscript in the example you provided and
trying my best to get what I can out of it. Thanks for all the comments!!!

Highly appreciated!!
Moe

tralfaz

2005-05-09, 11:14 pm

"moebetta" <webforumsuser@macromedia.com> wrote in message
news:d5mk6i$t39$1@forums.macromedia.com...
> Tralfaz,
>
> Just wanted to thank you for taking the time to help me out. I
> really
> appreciate it. I took a look at the example. I know it's better to
> put all the
> actions for your movie into one place. Typically, an actions layer
> on the root
> timeline. It seems to me that doing it that way requires more skill
> with
> actionscript than I have right now. I'll get a book in about a week.
> You know
> anygood ones on actionscript by chance? In the meantime I'll have to
> make the
> effect a bit more simple and get on with the rest of the gallery.
> I'll also be
> taking a really good look at the actionscript in the example you
> provided and
> trying my best to get what I can out of it. Thanks for all the
> comments!!!
>
> Highly appreciated!!
> Moe


Glad to help. For the AS book thing.. I would start with the video
training instead. It only costs $25 per month at lynda.com and $30
per month at vtc.com. For me it was better to watch the videos
first, then do the books later. You can try the first 3 chapters of
any video at vtc.com for free to see how you like it.
If you really want books, I recommend a book subscription service
called safari.com instead of buying books. For $9.99 per month you
can read 5 Flash books per month (or any other book they have) and
search all 2000+ books at any time for code examples.
good luck,
tralfaz







moebetta

2005-05-11, 7:24 pm

Tralfaz,

Just wanted to thank you for taking the time to help me out. I really
appreciate it. I took a look at the example. I know it's better to put all the
actions for your movie into one place. Typically, an actions layer on the root
timeline. It seems to me that doing it that way requires more skill with
actionscript than I have right now. I'll get a book in about a week. You know
anygood ones on actionscript by chance? In the meantime I'll have to make the
effect a bit more simple and get on with the rest of the gallery. I'll also be
taking a really good look at the actionscript in the example you provided and
trying my best to get what I can out of it. Thanks for all the comments!!!

Highly appreciated!!
Moe

tralfaz

2005-05-11, 7:24 pm

"moebetta" <webforumsuser@macromedia.com> wrote in message
news:d5mk6i$t39$1@forums.macromedia.com...
> Tralfaz,
>
> Just wanted to thank you for taking the time to help me out. I
> really
> appreciate it. I took a look at the example. I know it's better to
> put all the
> actions for your movie into one place. Typically, an actions layer
> on the root
> timeline. It seems to me that doing it that way requires more skill
> with
> actionscript than I have right now. I'll get a book in about a week.
> You know
> anygood ones on actionscript by chance? In the meantime I'll have to
> make the
> effect a bit more simple and get on with the rest of the gallery.
> I'll also be
> taking a really good look at the actionscript in the example you
> provided and
> trying my best to get what I can out of it. Thanks for all the
> comments!!!
>
> Highly appreciated!!
> Moe


Glad to help. For the AS book thing.. I would start with the video
training instead. It only costs $25 per month at lynda.com and $30
per month at vtc.com. For me it was better to watch the videos
first, then do the books later. You can try the first 3 chapters of
any video at vtc.com for free to see how you like it.
If you really want books, I recommend a book subscription service
called safari.com instead of buying books. For $9.99 per month you
can read 5 Flash books per month (or any other book they have) and
search all 2000+ books at any time for code examples.
good luck,
tralfaz







Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews