all groups > flash actionscript > may 2006 >
You're in the

flash actionscript

group:

Rediculously dumb Actionscript question


Re: Rediculously dumb Actionscript question David Stiller
5/17/2006 4:54:42 PM
flash actionscript:
guttyguppygmail,

[quoted text, click to view]

When you're dealing with objects, it's a lot like dealing with people:
just call your object by name and tell it what to do. In your case, you're
dealing with a movie clip, so your movie clip will have to have an instance
name (select the clip and look at the Property inspector). Once it has an
instance name, you can "call it by name" from the main timeline (or any
other) and tell it to do whatever movie clips can do.

And what can movie clips do? That's all spelled out in the MovieClip
class entry of the ActionScript 2.0 Language Reference. Classes define
objects. Characteristics the object has are called properties; things the
object can do are called methods; things the object can react to are called
events.

See this article for details.

http://www.quip.net/blog/2006/flash/actionscript-20/ojects-building-blocks

// in a frame of the main timeline
mcInstanceName.play();


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

Re: Rediculously dumb Actionscript question ImagicDigital
5/17/2006 4:54:49 PM
Also, don't forget to give your clip an instance name in the properties
panel after you drag it on stage. You'll need to use that instance name
Re: Rediculously dumb Actionscript question tralfaz
5/17/2006 6:06:48 PM
[quoted text, click to view]

None of these problems apply if you use a preloader on your swfs. Preloaders make sure things are all loaded before just running
things willy-nilly whenever they happen to load.
If you make sure everything is loaded before you run your main timeline you will be all set and things will work. All the
movieclips with a stop command in frame 1 will be sitting there waiting at frame 1 for the instruction to start. The problem gets
worse once you upload your file to the Web because of the slowness of loading.
Except for the most simple projects, almost all swfs should have a preloader to get things started cleanly.
tralfaz

Rediculously dumb Actionscript question guttyguppygmail
5/17/2006 8:23:17 PM
If I have a movieclip that tweens on the timeline, with a stop action on frame
1, and I put that movie clip on the root timeline, what actionscript should I
write on the root timeline to tell the movieclip to play? I run into this
roadblock almost every time I use flash, and forget how I solved it months
later when a new project comes up. Thanks for any advice.
Re: Rediculously dumb Actionscript question blemmo
5/17/2006 8:39:28 PM
You really forget <i>that</i>? wow... and I thought that I had a bad memory...
;)
So, some reminders:
myMC.play();
myMC.nextFrame();
myMC.gotoAndPlay(2);
myMC.gotoAndPlay(myMC._currentframe+1);

Also remember pressing the F1 key from time to time ;)

cheers,
blemmo
Re: Rediculously dumb Actionscript question guttyguppygmail
5/17/2006 9:15:26 PM
OK, thanks for the info. Here's what I'm doing:

make a new flash movie
draw a circle on the stage
make the circle into a movie clip called ball
name the instance ball
double-click on ball to edit it on its own timeline
add a stop action on frame 1
insert a keyframe on frame 10
drag the ball to the right on frame ten so its in a different place
go back to the root timeline
click on frame 1, type ball.play();
test movie
notice that the ball doesn't move, meaning it's not progressing past frame 1
of its timeline, even though you told it to play in the root timeline

What am I missing?

Re: Rediculously dumb Actionscript question blemmo
5/17/2006 9:26:32 PM
That's because of the code execution order. Flash goes from the top level (the
_root timeline) to the nested levels (the ball MC), and executes code in that
order. So it first executes "ball.play()", then enters the ball timeline and
executes "stop()". So the play() call doesn't do much here. It's good to keep
that in mind, it's the same when you attach an MC that has code in it's first
frame... can be really annoying.

So in this case, you could use ball.gotoAndPlay(2) instead, to play the ball
MC right away.

greets,
blemmo
Re: Rediculously dumb Actionscript question guttyguppygmail
5/17/2006 9:29:24 PM
Re: Rediculously dumb Actionscript question blemmo
5/17/2006 9:59:52 PM
uhm, yep. Well, it seems it does execute the stop() in frame 1 of ball anyway
when loading, so it stops the MC, but still goes to frame 2, because that was
told in the main timeline. It's really not intuitive, but I guess it has some
logic in it... it has to execute the code in frame 1 of the ball MC when the
movie loads, but that is after the _root's code executes, which tells the MC to
play the second frame. So it still executes the code from the main timeline,
but only after the code in the MC's frame 1, resulting in a stop at frame 2.

Hm... not so sure if this is logical anymore... but I guess the Flash people
had to decide on this execution order somehow, and accept the possible
drawbacks, like this situation here.

If you add a frame in the main timeline and call ball.play() there, and it's
doing as expected. I think it's just going wrong because it's all happening
right at the initialisation of the movie.

hth,
blemmo
Re: Rediculously dumb Actionscript question tralfaz
5/17/2006 10:59:34 PM
[quoted text, click to view]

I can't see the code because my Flash is version 6 but i've seen so many cases where a file just does funny stuff on startup because
things happened out of sequence. Preloaders that are written right usually fix that. They make it so that the main timeline
doesn't run any code actions on movieclips in the first frame and nothing gets activated until the preloader says everybody is
loaded. If I could see the swf I could find the problem me thinks.
tralfaz

Re: Rediculously dumb Actionscript question Craig Grummitt
5/18/2006 12:00:00 AM
so you can replicate this issue yourself with Flash 6, here's what's contained
in the fla:
---------------------------
_root:
Frame 1: "Preloader"
stop();
if(_framesloaded==_totalframes) {
play();
}

Frame 2: (A movie clip on stage with instance name 'ball')
stop();
ball.play();
--------------------------
Ball Movie Clip:
Frame 1:
stop();

Frames 1-15:
Something to indicate movement or a change in frames

Re: Rediculously dumb Actionscript question Peter Blumenthal
5/18/2006 12:00:00 AM
[quoted text, click to view]

Lol - someone obviously forgot to tell my wife and daughters that that's how
people work :))

--
-------------------------------
Remove '_spamkiller_' to mail
-------------------------------

Re: Rediculously dumb Actionscript question guttyguppygmail
5/18/2006 12:28:24 AM
Re: Rediculously dumb Actionscript question tralfaz
5/18/2006 12:38:12 AM

[quoted text, click to view]

I know you are trying to help but you should know you can't run a preloader in one pass, you have to call it repeatedly.

[quoted text, click to view]

You don't need to move it to frame 2.

With the ball movieclip on frame 1 like it originally was..

// a working preloader on frame 1 of main timeline..
this.onEnterFrame = function()
{
var gbt = this.getBytesTotal();
var gbl = this.getBytesLoaded();
if (gbt && (gbl == gbt)) // not zero, and matching
{
delete this.onEnterFrame; // not needed anymore
ball.play(); // start the ball
}
}

It works fine, if you wait for the file to load before calling ball.play();
tralfaz





Re: Rediculously dumb Actionscript question guttyguppygmail
5/18/2006 2:10:59 AM
Ok, I tried my ball example and added a simple preloader to it,and still the
ball does not play. If you want to take a look at the fla file I made, it's
here:
<a target=_blank class=ftalternatingbarlinklarge
href="http://www.fieldii.com/test.fla.zip
I">http://www.fieldii.com/test.fla.zip
I</a> know I'm missing something fundamental about the way flash works,
Re: Rediculously dumb Actionscript question Craig Grummitt
5/18/2006 4:26:40 AM
yeah flash can be a little unintuitive sometimes with the order it follows
contradictory instructions(ie stop? gotoandplay? aaagh! how about gotoAndstop
instead?).

here are three simple alternatives to get around this issue(and i'm sure there
are many more)
1 - move the ball stop from the first frame to the second and gotoAndPlay 3.
2 - move the gotoandPlay on one frame so that the stop in ball has had a
chance to do its thing before the playhead reaches the gotoandplay..
3 - put a play() on frame 2 of ball.

i'm afraid that wasn't really a preloader guttyguppygmail, it was a simple one
off test that all assets were loaded. however a preloader doesn't appear to
help this particular situation anyway tralfaz, although i think i know what
you're talking about - going to a specific frame of the _root when it hasn't
loaded yet causes problems.
Re: Rediculously dumb Actionscript question David Stiller
5/18/2006 10:06:56 AM
Peter,

[quoted text, click to view]

Ha. ;) I was referring, actually, to my wife telling *me* what to do.
:-p


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

Re: Rediculously dumb Actionscript question tralfaz
5/21/2006 7:23:01 PM
[quoted text, click to view]

Oh, ok then. I misunderstood. I thought it was your code. Sorry.

[quoted text, click to view]

I have been through this before (years ago) and I can tell you that delaying by one frame may or may not work depending on the
slowness off the loading. Combine a slow computer with a slow connection and you could have a malfunction. A long time ago I had
been doing exactly what you said.. delaying the start of a clip until X number of frames but the results were not reliable with
various browsers and connnections. A preloader makes sure it's ready regardless of the outside circumstances.
Because I have a high speed connection, I would think that my flash project worked perfectly. Then when I was somewhere else and
tried to show it to people on their slower connections the thing wouldn't run.. reason.. I was using the delay by frame method. I
learned this the hard way! Now I use preloaders to be sure it will work.

[quoted text, click to view]

When the preloader is done you can play the main timeline. When it reaches the frame with the movieclip in it you can put
ball.play() in a keyframe there.
If you have a preloader in frame 1, it cannot directly address the ball in frame 2 because in frame 1, ball does not exist so the
code doesn't assign correctly.

Anyway, thanks for helping on the forum and sorry for the misunderstanding.
'ave a gud 1
tralfaz







Re: Rediculously dumb Actionscript question Craig Grummitt
5/21/2006 11:54:23 PM
i don't think you understood tralfaz - my previous post wasn't an attempt at a
solution, it was merely explaining to you what was in guttyguppygmail's fla as
you said you couldn't see the code as you had flash 6.

"I know you are trying to help but you should know you can't run a preloader
in one pass, you have to call it repeatedly."

i know that this isn't a preloader which is why i put the word in quotation
marks and said in an earlier post "i'm afraid that wasn't really a
preloader..." and explained why.

what you have done, tralfaz, is given flash at least a frame to activate the
stop action in the circle clip, and then the ball.play() action in your
preloader works fine. its not the preloader that is resolving this problem,
it's the onEnterFrame. it would work just as well if you used the following
script on frame 1(if the ball movieclip is on frame 1):

this.onEnterFrame = function() {
ball.play();
};

"You don't need to move it to frame 2."

my point is that a preloader doesn't resolve this problem. what i'm interested
to know is what your solution is if the circle movie clip is on frame 2.
Re: Rediculously dumb Actionscript question Craig Grummitt
5/22/2006 3:02:41 AM
sorry to labour this point, (you're probably sick of it by now!) but i'm still
curious about this point and i'm still not sure you understand what i'm saying.
maybe i'm not writing clearly - i'll try again.

i completely understand the value of preloaders. i am not suggesting that the
movie doesn't start until X number of frames. what i am saying is that in this
case the problem seems to exist whether you have a preloader or not.

i am not suggesting that after the preloader is loaded it tries to goto a
frame in the circle mc (that would be just silly if the circle mc isn't on the
stage yet). i was suggesting that the preloader would then navigate to a frame
in the main timeline - let's call it frame 2.

on this frame(2) the circle MC is introduced, which has a stop() on its first
frame. ok now here's the problem - on the main timeline, if we were to write
circle.play(), the circle would not play. if we were to write
circle.gotoAndPlay(2) to attempt to get around that problem, the circle
strangely goes to frame 2 and stops(!).
Re: Rediculously dumb Actionscript question tralfaz
5/22/2006 11:03:16 AM

[quoted text, click to view]

Yes, I understand what you mean.

1) _root timeline says circle.play();
2) circle movieclip frame 1 says stop();
that cancels the play command from the _root before any screen updates occur.
So, now why we can't have circle.gotoAndPlay(2) on the _root without still getting the stop() on frame 1 of the movieclip?
Someone who knows more of the internal workings (like Jeckyl maybe) might be able to clear it up.

FWIW If I were going to put the movieclip on frame 2 and have it play as soon as the timeline reached frame 2 I wouldn't put a stop
on the movieclip frame 1 anyway. It will just start playing when it's instantiated.

tralfaz




Re: Rediculously dumb Actionscript question tralfaz
5/22/2006 2:23:40 PM
[quoted text, click to view]

Sounds right to me blemmo. The main question in my mind was whether the movieclip's frame 1 code could be bypassed. It sounds like
that the code in frame 1 always executes during the instantiation whether you try to jump past it or not.
tralfaz

Re: Rediculously dumb Actionscript question blemmo
5/22/2006 8:55:41 PM
<blockquote>quote:<br><hr><i>Originally posted by: <b><b>Newsgroup
User</b></b></i>
1) _root timeline says circle.play();
2) circle movieclip frame 1 says stop();
that cancels the play command from the _root before any screen updates occur.
So, now why we can't have circle.gotoAndPlay(2) on the _root without still
getting the stop() on frame 1 of the movieclip?
<hr></blockquote>

Same reason: because the code of circle executes after the code in _root, and
the first appearance of circle is in the same frame. So it has to play frame 1
of circle and execute the stop(), which will stop the play part of
gotoAndPlay(2).
It mixes up the time order here, I'd say. First is the code from _root
followed by the code in circle's frame (which should be frame 2 now, without
any code), but now there's still the code from frame 1 of circle to execute,
because it was instantiated in that frame. So basically, the stop() of frame 1
overrides the _root action here, what I thought shouldn't be possible because
of that code execution scheme...
Well, it's all just happening when the MC instantiates, so in other setups
this shouldn't appear.
<blockquote>quote:<br><hr>
FWIW If I were going to put the movieclip on frame 2 and have it play as soon
as the timeline reached frame 2 I wouldn't put a stop
on the movieclip frame 1 anyway. It will just start playing when it's
instantiated.
<hr></blockquote>
Exactly. :)

Besides, in this setup here, a play() in frame 2 of circle would also do it,
but even then, it would only work out when _root says gotoAndPlay(2), not frame
50 or any others. So it's definitely a wrong setup, with a stop() at a very
wrong place.

greets,
blemmo

Re: Rediculously dumb Actionscript question tralfaz
5/24/2006 10:34:05 AM
[quoted text, click to view]

Confused.. gotoAndStop doesn't work with instance names in the parens.. ("instancenames")
It can take a frame label there though.
tralfaz

Re: Rediculously dumb Actionscript question respondplease
5/24/2006 3:37:16 PM
Hi all,

Great post and info provided. After hours and hours of researching and a
couple of posts that I received no feedback on (I'm aight....not
offended...j/k!) I managed to figure out my AS:

on (release) {
instanceName.gotoAndPlay(2);
_root.gotoAndStop ("instanceName");
}

Just thought I'd share in hopes. Thanks again!!
Re: Rediculously dumb Actionscript question respondplease
5/24/2006 7:51:59 PM
Tralfaz,

AddThis Social Bookmark Button