Welcome to TalkGraphics.com
Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Sep 2000
    Location
    Boca Raton, FL
    Posts
    14

    Default

    I'd like to set a variable on a button click in the main movie and be able to pass that variable's new set value to the loaded movie for evaluation there.

    This is what I did in the main movie...

    on (release) {
    loadMovieNum ("profileinterface.swf", 2);
    }
    on (release) {
    selection = "1";
    }


    and the evaluation of it in the loaded movie...

    if (selection = 1) {
    gotoAndPlay (1);
    } else if (selection = 2) {
    gotoAndPlay ("bigpicture");
    } else {
    gotoAndPlay ("phil");
    }


    something isn't working....Can a loaded movie read a variable set in another movie?

    any help would be appreciated!!
    IP

  2. #2
    Join Date
    Sep 2000
    Location
    Boca Raton, FL
    Posts
    14

    Default

    I'd like to set a variable on a button click in the main movie and be able to pass that variable's new set value to the loaded movie for evaluation there.

    This is what I did in the main movie...

    on (release) {
    loadMovieNum ("profileinterface.swf", 2);
    }
    on (release) {
    selection = "1";
    }


    and the evaluation of it in the loaded movie...

    if (selection = 1) {
    gotoAndPlay (1);
    } else if (selection = 2) {
    gotoAndPlay ("bigpicture");
    } else {
    gotoAndPlay ("phil");
    }


    something isn't working....Can a loaded movie read a variable set in another movie?

    any help would be appreciated!!
    IP

  3. #3
    Join Date
    Aug 2000
    Location
    Toronto, Ontario, Canada
    Posts
    432

    Default

    Try:

    on (release) {
    loadMovieNum ("profileinterface.swf", 2);
    selection = "1";
    }

    Then from the loaded movie

    myNewVar = _level0.selection; // read the variable

    // you might want to check to see if this
    // is the correct way to reference a
    // different level

    // check which frame should play
    if (myNewVar = 1) {
    gotoAndPlay (1);
    } else if (myNewVar = 2) {
    gotoAndPlay ("bigpicture");
    } else {
    gotoAndPlay ("phil");
    }


    hth,
    Deep (just a guy)

    <pre><font face="courier" size="2">,-----------------------------.

    | Pradeep Kumar Nair, B.Math |

    | Graphic/Multimedia Designer |

    | ICQ#: 39102360 |

    | Medius Communications, Inc. |

    | http://www.medius.com |

    `-----------------------------'</font></pre>
    Moderator - i/us Flash Forum
    hth,
    Deep (just a guy)
    --
    Pradeep Kumar Nair, B.Math
    CTO
    9 Story Entertainment
    http://www.9story.com
    IP

  4. #4
    Join Date
    Sep 2000
    Location
    Boca Raton, FL
    Posts
    14

    Default

    I tried your suggestion verbatem and at first, it seemed to work. Upon further testing, however, it does not appear to evaluate the variable from level 0 correctly and do the action.

    What I REALLY need to do with this is controll a movieclip on the main timeline of the movie in level2 based on the value set by the button click in level0. Here's what I tried:

    //this is used on the button in level0

    on (release) {
    loadMovieNum ("profileinterface.swf", 2);
    selection = "1";
    }

    then this was added at frame 23 of scene 1 in the loaded movie on level2 (content is the name of the movieclip I'm trying to control...it should be ref.'d right here as this is what the target feature in Flash 5 spits out):

    // read the variable
    choice = _level0.selection;

    // check which frame should play
    if (choice=1) {
    tellTarget ("content") {
    gotoAndPlay (1);
    }
    } else if (choice=2) {
    tellTarget ("content") {
    gotoAndPlay ("bigpicture");
    }
    } else if (choice=4) {
    tellTarget ("content") {
    gotoAndPlay ("why");
    }
    } else {
    tellTarget ("content") {
    gotoAndPlay ("phil");
    }
    }

    //stop the main timeline from progressing
    stop ();

    Based on what I already know and what it says in some of the help files, the way to ref a level is like you said (_levelX), but can you ref a lower level that way? Maybe that's the problem?

    Again, thanx for all the help!!!
    IP

  5. #5
    Join Date
    Aug 2000
    Location
    Toronto, Ontario, Canada
    Posts
    432

    Default

    First off, try not to use the TellTarget action - it's deprecated, so this code won't carry over to later versions of Flash. Somebody had pointed that out to me, earlier, in this forum, and suggested using the "with" action, instead.

    Secondly - where is the movie clip "content" located? Is it in layer 2? Or is it in the same layer as your variable, "selection"? You'll need to put the right path to the target clip, as well. If you're doing it using the targetting option from Flash 5, then it should work fine - so don't sweat it. Otherwise, make sure your code is correct.

    Lastly, if none of the above seems to work, or if you're sure they're not the problem, try changing the value of choice to "1" or "2", etc., instead of just 1 or 2. It might be that it's trying to read it as a string instead of an integer.

    Try using the debugger to set a watch on the variable choice and see what it pops up when it checks the value of selection.


    hth,
    Deep (just a guy)

    <pre><font face="courier" size="2">,-----------------------------.

    | Pradeep Kumar Nair, B.Math |

    | Graphic/Multimedia Designer |

    | ICQ#: 39102360 |

    | Medius Communications, Inc. |

    | http://www.medius.com |

    `-----------------------------'</font></pre>
    Moderator - i/us Flash Forum
    hth,
    Deep (just a guy)
    --
    Pradeep Kumar Nair, B.Math
    CTO
    9 Story Entertainment
    http://www.9story.com
    IP

  6. #6
    Join Date
    Sep 2000
    Location
    Boca Raton, FL
    Posts
    14

    Default

    Well, other than using the with action (I'm not YET familiar with it), I haven't been successful. I tried altering the choice = "2" etc as suggested...I also tried changing selection = "2" and without the quotes. NADA.

    The content clip lives in level 2. To be sure it wasn't a tell target issue, I just tried to evaluate the variable and tell the timeline to go to another scene.

    Oddly, at the frame where the movie was to make the evaluation, the movie would go to where I specified no matter what I set in the if statement. I thought that if it was not successful in the first if, it would then do the else..it didn't.

    I tried testing a basic variable set without all the other junk:

    I set the variable choice and then tried to evaluate it and do something...

    choice = "bill";
    if (choice="bill") {
    gotoAndPlay ("hide", 1);
    } else {
    loadMovieNum ("newsinterface.swf", 4);
    }
    stop ();

    Well, in the debug list, it shows choice="bill" yet the movie performs the else action and loads the other movie! I tried bill with and without the "" in both places.

    I'm really stumped now! I can't even get a variable to set and be read right!! AARGH [img]/infopop/emoticons/icon_mad.gif[/img]

    I may just resolve to creating 4 copies of the movie to be loaded into level 2, each having a basic goto telling it where to start. Essentially, that's exactly what the passing of the variable would have done (if it worked). I'll just tell each of the 4 buttons in level 0 to load the correct version of the movie!

    YUK!! What an inefficient method!! Any other ideas?
    IP

  7. #7
    Join Date
    Aug 2000
    Location
    Toronto, Ontario, Canada
    Posts
    432

    Default

    ...but try using if (choice == "bill") instead of if (choice = "bill").

    I know it sounds odd, but that's how JS works, and I know Flash 5 is trying to bring itself closer to JavaScript - so try the standard operand.

    Alternately, try and test the value of the variable. Create a dynamic text box, with the variable named "choice" - that way, whenever you set the variable "choice" it should update its value in that text box, so you can see what's going on. At least you have a definite way of knowing that it's been transferred correctly (I've heard too many horror stories of people trying to use the debugger and getting odd results).


    hth,
    Deep (just a guy)

    <pre><font face="courier" size="2">,-----------------------------.

    | Pradeep Kumar Nair, B.Math |

    | Graphic/Multimedia Designer |

    | ICQ#: 39102360 |

    | Medius Communications, Inc. |

    | http://www.medius.com |

    `-----------------------------'</font></pre>
    Moderator - i/us Flash Forum
    hth,
    Deep (just a guy)
    --
    Pradeep Kumar Nair, B.Math
    CTO
    9 Story Entertainment
    http://www.9story.com
    IP

  8. #8
    Join Date
    Aug 2000
    Location
    Toronto, Ontario, Canada
    Posts
    432

    Default

    here's an example of what i mean. export the two movies then run firstmovie.swf. you'll see that it says you're not in canada yet. now open firstmovie.fla and change the variable to say "hello", export it again and run it. this time it says the "eh" message. look at the code in loadIt.fla to see exactly how i called the variable and used it. maybe this will give you the insight you need to make your code work.


    hth,
    Deep (just a guy)

    <pre><font face="courier" size="2">,-----------------------------.

    | Pradeep Kumar Nair, B.Math |

    | Graphic/Multimedia Designer |

    | ICQ#: 39102360 |

    | Medius Communications, Inc. |

    | http://www.medius.com |

    `-----------------------------'</font></pre>
    Moderator - i/us Flash Forum
    Attached Files Attached Files
    hth,
    Deep (just a guy)
    --
    Pradeep Kumar Nair, B.Math
    CTO
    9 Story Entertainment
    http://www.9story.com
    IP

  9. #9
    Join Date
    Sep 2000
    Location
    Boca Raton, FL
    Posts
    14

    Default

    Your test works perfect in your movies, but when I transfered the knowledge and ideas to mine...no luck...BUT..I may have identified the problem.

    The buttons that sets the variable in the level 0 movie are in a movieclip on the timeline. I think that that fact is keeping the variable from getting set properly.

    To test this theory, I created a regular button on the stage (not in a movieclip), assigned in onclick set variable action and the loadmovie action and it all worked. I then put the same button INSIDE the movieclip on the timeline and it did not work.

    So it seems as if the variables are being set INSIDE the movieclip but not for the level 0...?? Do I have to pass the variable first back to the main timeline fromthe movieclip somehow so that the loaded movie on level 2 can see it (as in your example)?

    See the attached version of your firstmovie.fla file. I added a movie clip containing a button with the actions (like in my movie). See how it does not pass the variable correctly.

    Again, thank you thank you thank you for your help!!
    Attached Files Attached Files
    IP

  10. #10
    Join Date
    Aug 2000
    Location
    Toronto, Ontario, Canada
    Posts
    432

    Default

    oops! you need to target the movieclip. in the file you sent me, you didn't give the movieclip an instance name (look at the instance palette). i named it bob. that way, in loadIt, i was able to reference the variable like so:

    myDisplayVariable = _level0.bob.myLittleVariable;

    note the added thingy in the middle? yes, i call it a thingy. i always was very scientific, you know. [img]/infopop/emoticons/icon_smile.gif[/img]

    let's look at it through the idea of an analogy: say bob has a pen that you want to borrow. you know he has a pen, in fact, bob is known for carrying hundreds of pens about his person. but you want a specific pen - one that writes with gold ink. but you can't just point at bob and expect to be pointing directly at the golden stylez pen. you have to point at exactly the right pocket (let's say...um...his right breast pocket. yeah, that's the ticket) before he can figure out which pen to give you.

    in other words:

    giveMePen = _levelBob.goldenpen;

    won't work. but

    giveMePen = _levelBob.rightBreastPocket.goldenpen;

    would! and if bob was being a special pain in the buttocks that day, maybe he had two pocket protectors today - and both were in his right breast pocket. well:

    giveMePen = _levelBob.rightBreastPocket.Protector2.goldenpen;

    would work! See what I'm getting at? In Flash, you'd have to target the object directly - starting with _level (if it's on a diferent level), then movie clip, then subclip, all the way until you hit the object.

    hopefully this helps! Oops - i think i got a bit long-winded there, but i hope you don't mind. i think i miss teaching. [img]/infopop/emoticons/icon_biggrin.gif[/img]


    hth,
    Deep (just a guy)

    <pre><font face="courier" size="2">,-----------------------------.

    | Pradeep Kumar Nair, B.Math |

    | Graphic/Multimedia Designer |

    | ICQ#: 39102360 |

    | Medius Communications, Inc. |

    | http://www.medius.com |

    `-----------------------------'</font></pre>
    Moderator - i/us Flash Forum
    hth,
    Deep (just a guy)
    --
    Pradeep Kumar Nair, B.Math
    CTO
    9 Story Entertainment
    http://www.9story.com
    IP

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •