I know that variables in moviclips are local. I am using a multipage contentpane to show some texts. I think that when the user clicks on the arrow to advance to the next page a variable called "pagenumber" is incremented. I want to use this information to link to a given audio file. That is, when the user chooses a page, I will use the value in "pagenumber" to determine which audio file is played when he hits the play audio button.
To test this, I created a dynamic textbox and added the AS "txt1var = pagenumber" but when I run it, the display is "Undefined." Makes sense, since "pagenumber" is in MC1 and so is local. Following info on a thread here, I tried adding "_global." on both sides of the assignment with no luck. Naturally, "mc1.pagenumber" is also an absurdity to KM. So how can I read the value in a variable within a movieclip?
BTW, entering all the pages by hand is tedious, especially since the interface does not remember that I am adding files and not using transitions and you can't select multiple files in the file selector. You have to do a lot of clicking. It would be nice if the interface remembered your last choices.
I know I could do this with actionscript as in the KC8Demo. I tried to follow that and the API in the Flash 8 Examples folder and the Users Guide, but the code eludes me. Is there more newbie-oriented information somewhere about using the components with AS? These components are terrific, so I want to learn how to get the most from them.
Last edited by jimventola; 08-08-2006 at 01:57 PM.
Reason: add info
I did notice that a search for "pagenumber" in that script came up empty. But now I think this is just a parameter, maybe a boolian to turn pagenumber on and off? As you see, I am flying blind here.
Still, the page number does appear (you can even set the color in the options) so it must be available.
The pagenumber parameter in the c array you are referring to is just the text color of the page number.
Edit:
If you wish you can combine it with the onTransit event to more or less sync it.
I thought to suggest that but from reading the API info I wasn't entirely sure that was the way to go. But I think that's exactly what he was looking to do
I'm hoping the way we construct (concatenation) dynamic variables becomes clear. Whether a "foo" we create or a "v" we scarf from what exists (as part of the component variables) he's understanding how it all works bit by bit. Right Jim?
If you don't have to display it, you can even combine it...The pagenumber parameter in the c array you are referring to is just the text color of the page number.
Elegant! Since the contentpane already displays the page number, I won't have to display it.
I had a hunch I was assuming too much from the semantics of "pagenumber" but that it meant color I would never have figured.
I'm hoping the way we construct (concatenation) dynamic variables becomes clear. Whether a "foo" we create or a "v" we scarf from what exists (as part of the component variables) he's understanding how it all works bit by bit. Right Jim?
Yes indeed, Chris. Bit by itsy bitsy bit. But Oh what fun!
The more you realize you can skin the cat multiple ways...the more ideas pop in your head. All Wilberts components have those little dippers of data you can dip into. Without doubt one the five best reasons to buy this program are those puppies.
Actually this is fine, I imagine though that pagenumber is just not set.
Friends,
I have been working on this same problem.
First of all you should know this thread came up with a Google search for "koolmoves movie clip event can't read movie clip variables"
I have a variable (msg = "Hello World!") declared in an actionscript statement located on a frame within my movieclip's timeline.
However, I want to call on that variable from an onClipEvent handler which is assigned to the movieclip itself.
If I assign a similar handler to a button on the other hand, there's no problem:
on(Press)
{
_root.txt1var = mc1.msg
}
...renders the familiar Hello World! statement in my root timeline text box.
However, the same statement when assigned to the movieclip does *not* produce results, and this bugged the heck out of me because I really do need actionscript in both parts of the MC (as a clip event and in the frames).
I finally figured out what was happening when I got curious and assigned this clip event to the movieclip:
on(Press)
{
_root.txt1var = this; // what's my name for crying out loud?
}
...and found out that mc1 has been thinking of itself as _level0.mc1
After that I had no problem accessing variable msg as _level0.mc1.msg.
A very minor discovery, to be sure, but one that bugged me for a good hour.
And I wonder if this explains why jimventola had so much trouble accessing a variable within a movieclip, even though (as blanius noted) it should have been entirely possible.
I beleive _level0 is the same thing as _root and indeed if you need to access a variable in mc1 from whithin another clip you'd have to refer to it _root.mc1 or _parent.mc1
_root is a direct reference to the main timeline of the current level. This means that witihin an mc within _level2, _root refers to the main timeline of _level2.
No don't think so... _root is just that _root it is the swf that is into which all else is loaded. This is why it's better to use _parent if you don't know at what level you movie will reside. so mc1's full name is _level0.mc1 or _root.mc1
try this.Create a textfiled on the stage, Put a clip on the stage . Add this code to the clip mc1's time line
_root.txt1.text="hi from "+this
and you will get hi from _level0.mc1 in the text box.
Now change _root to _level0 and you will see that it still works.
So _root and _level0 are the same. Unless your clip uses lockroot command.
try this.Create a textfiled on the stage, Put a clip on the stage . Add this code to the clip mc1's time line
_root.txt1.text="hi from "+this
and you will get hi from _level0.mc1 in the text box.
Now change _root to _level0 and you will see that it still works.
So _root and _level0 are the same. Unless your clip uses lockroot command.
I'm a little pressed for time, so I can't give my usual really detailed and heavily researched essay answer, but your example above is consistent w/ my answer, rephrased as follows: _root within _leveln = _leveln. Your example is limited to _level0, so of course it works. _level0 = the original document loaded into the flash player.
In a movie w/ only one level, by default _root = _level0. All swfs start at _level0 when they are created, but swfs can be loaded into other swfs at levels other than _level0, ie, multiple level projects are created by loading swfs into levels other then _level0. It is a means of creating modular programming with independantly developed modules. It is also why _root is so important - if you create a swf (x.swf) that is going to be loaded into another swf's levels (y.swf), then 1) coding _level0 in x.swf will refer to the main timeline of y.swf when x.swf is loaded into _level(n>0), but 2) coding _root in x.swf will always refer to the main timeline of x.swf, regardless of what level x.swf is loaded into in y.swf.
If x.swf is loaded into _level0 of y.swf, it in effect replaces y.swf in the flash player. This is usually a bad idea, unless you are daisy-chaining swf execution. This was actually covered a while back as a way to circumvent flash player swf size limitations.
Levels are used to organize the "document stack" - movies (swfs) that are running together but not nested - sort of running in parallel. You would use the _leveln.mcn.varname path syntax to communicate between these movies running simultaneously within the flash player (passing values or controlling clips). By convention, _level0 usually contains the code that coordinates the actions of the swfs in the other levels, and the frame rate defined in the movie loaded into _level0 is applied to all the movies running in the other levels - I can't recall if the frame rate changes if a new swf is loaded into _level0; I don't think it does.
Gotta go, hope this didn't confuse you any worse. I think Remus is the most experienced w/ using levels.