A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Read variable from mc?

  1. #1
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205

    Read variable from mc?

    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

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    if the contentpane is in mc1 then you can query the current page with mc1.contentpane1.getPage()

    Not sure if there is an event you can watch for. Maybe onTransit

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    "mc1.pagenumber" is also an absurdity to KM. So how can I read the value in a variable within a movieclip?
    Actually this is fine, I imagine though that pagenumber is just not set.

  4. #4
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205
    Well, maybe my assumption is wrong. I was basing it on this from the contentpane AS

    Code:
    /* ** KC8 ContentPane ***
    
     properties :
    
     c [track, bar, button, arrow, background, textpaper, pagenumber] : colors
     s [raise, angle, component shadow alpha] : styling options
     _x, _y : location
     autoHide : 0=none, 1=horizontal scroller, 2=vertical scroller, 3 = both scrollers
    
    */
    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.

  5. #5
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    contentpane has function getPage() for just that usage....

    Look in API document.

  6. #6
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244

    example

    here is this what you want to do?
    Attached Files Attached Files

  7. #7
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205

    Most excellent

    That's it. Thanks so much.


    So then, after

    Code:
    _root.txt1.text=contentpane1.getPage()
    I could do something like

    Code:
    foo = _root.txt1.text
    and then use foo in a string to manipulate which file is used?

    Chris gave me this code
    Code:
    root.mySound = new Sound(mySprite);
         _root.mySound.loadSound("song"+foo+".mp3", true);
    So would foo now correctly add the pagenumber to the mp3 filename?

    (I am really not too lazy to try, but I wanted to get the code into this thread in case any future forum searchers want to use this approach.)

    Again, thanks so much for the help.

  8. #8
    Senior Member
    Join Date
    Dec 2002
    Location
    Netherlands
    Posts
    1,632
    If you don't have to display it, you can even combine it
    Code:
    mySound.loadSound("song"+contentpane1.getPage()+".mp3", true);
    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.
    Last edited by w.brants; 08-08-2006 at 03:32 PM.

  9. #9
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    mySound.loadSound("song"+contentpane1.getPage()+". mp3", true);
    That's the ticket right there

  10. #10
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by w.brants
    If you don't have to display it, you can even combine it
    Code:
    mySound.loadSound("song"+contentpane1.getPage()+".mp3", true);
    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

  11. #11
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    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?

  12. #12
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205
    Quote Originally Posted by w.brants
    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.

    Thanks for the component and the help.

  13. #13
    Senior Member
    Join Date
    Feb 2004
    Location
    Halifax, MA
    Posts
    205
    Quote Originally Posted by Chris_Seahorn
    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!

  14. #14
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    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.

  15. #15
    Junior Member
    Join Date
    Sep 2004
    Location
    new Location("Toto").is(!Kansas)
    Posts
    3

    When mc1.foo = undefined; // funny KM bug...

    Quote Originally Posted by blanius
    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.

    Anyone care? :-D

  16. #16
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    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

  17. #17
    Senior Member pherbrick's Avatar
    Join Date
    Jul 2004
    Location
    Los Angeles
    Posts
    291
    _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.

  18. #18
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    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.

  19. #19
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    If I read him right all oz_emb had to do was use
    Code:
    on(Press)
    {
    _root.txt1var = msg
    }
    or
    Code:
    on(Press)
    {
    _root.txt1var = this.msg
    }
    the way it is now
    on(Press)
    {
    _root.txt1var = mc1.msg
    }

    would send the variable msg from a clip called mc1 within mc1.

  20. #20
    Senior Member pherbrick's Avatar
    Join Date
    Jul 2004
    Location
    Los Angeles
    Posts
    291
    Quote Originally Posted by blanius
    No don't think so... {explanation deleted}

    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.

    Peter
    Last edited by pherbrick; 09-05-2006 at 05:07 PM.

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