Passing a variable from a movie clip to the main timeline

Hi,
I'm having trouble passing a variable from a movie clip in my
flash file to the main timeline.
I have a movieclip with the instance name IntroNav which
contains several buttons. Clicking a button sets the variable
"page" to a specific name, i.e. page = "home"
However, outside of the movie clip, on the main timeline I am
unable to call this variable, and "page" seems to have no value.
Can anyone tell me why this is and how to solve it?
Thanks

Umm, yes ... declare your variables correctly.
var page:String = new String(); //proper complete
var page:String; //strict typing
var page:String = "home"; //stirct typing with value
declaration
Do not declare the variable in your buttons, you would have
to do so in every button and be constantly resetting the value.
Declare it on the main timeline at the lowest level. You do not
need to use it as a _global, you just need to resolve your path
issues. You can 'set' the variable value from a button, without any
problem, but you have to call to the variable correctly.
You do not 'name' a variable as "_root.page" , the '_root'
refers to the lowest level of the SWF or the main timeline, as does
a call to ' _level0' (that's a zero). If the variable is declared
on the main timeline, and you're calling from the MC/button or
anywhere you can refer to the variable by calling to it by
the proper path of '_root.page'
To set the variable from any of your button/MC instances
call:
_root.page = "value"; OR _level0.page = "value";
But you must have the varibale declared on the main timeline,
and only once and the playhead should be stopped or it will reset
the value to the default upon looping.

Similar Messages

  • How do I recerence Movie Clips on the Main Timeline from inside a class?

    Hey everyone, this might be a stupid question but I thought
    I'd ask cause it's making me nuts. I'm all of 2 days into AS3
    (coming from not using Flash at all in YEARS) so feel free to
    consider me ignorant. I do have plenty of application development
    experience in other areas though.
    I can't seem to create a class that can reference an instance
    of a movie clip on my main timeline. I'd post code of what I've
    tried but I've gone through so many desperate edits & wild
    guesses that it was just garbled junk before I deleted it all.
    Basically here's how I figured Flash could work, though maybe
    it doesn't work this way at all.
    I'm assuming that with AS 3 being so big on being a true
    object oriented environment, I wouldn't need to mix my code and
    interface together. Preferably I'd be using the Flash authoring
    tools just to design my interface. Create a button... place it
    somewhere... give it an instance name. Roughly the equivilant of
    Apple's InterfaceBuilder for those of you that might be familiar
    with Cocoa development. I can see maybe having to put a few lines
    of ActionScript onto frame 1 (though really I'm hoping Flash would
    have a better method of kicking off the application at this point
    that using code tied to frames) to load my classes & such, but
    after that I'd like all of my code to be held in external class
    files.
    So maybe I've got:
    Interface.fla - My interface
    Button_1
    Button_2
    TextField_1
    Main.as - My main controller class using to handle all of my
    applications behavior
    SomeClass.as - Some helper Class
    SomeOtherClass.as - Some helper Class
    Main.as would have instructions in its initialization method
    to go ahead & attach events to buttons & initialize
    anything else that needs to happen when the application starts.
    From there on it would all be objects communicating back &
    forth. Button_1 would get clicked with would fire
    Main.someMethod(). Main.someMethod() would then do it's thing and
    set the value of TextField_1. All very clean & code is very
    separated from interface.
    Unfortunately I can't for the life of me figure out how AS3
    classes reference each other like that. There doesn't seem to be
    any kind of a global 'root' or '_root' I can use to locate any
    movie clips on the stage. I've searched the help & the web for
    any kind of simple tutorial but to no avail. My job has tasked me
    with building a flash app for a project but I'd really rather not
    have a tone of ActionScript just shoved into frame 1. That just
    seems... ugh! (::shudder::)
    Can someone maybe point me in the right direction here? I'm
    really willing to do my homework but I can't seem to locate the
    info I need to get started. Also, is there an ActionScript IRC
    channel or something maybe?
    Thanks,
    Cliff

    I worked with the problem last night and the solution I
    started coming to involved creating my own custom document class
    based off which extends MovieClip. My thought is that way I have
    access to the initialization routine of the timeline itself and
    that all of the elements on the main timeline should be
    "properties" of my custom class.
    Is this correct? Is there a down side to doing this & if
    so what is it & why?
    Also, just for my reference, the last time I did anything
    with ActionScript I think I was using '_root' to target the main
    timeline. WHat are the global variable names in AS 3? Is it just
    'root' & 'stage' or 'Root' & 'Stage' or what?

  • Controlling a Movie Clip on the Main Timeline from a loaded SWF?

    Is it possible to control a MovieClip on the main timelne from another loaded clip?
    I see posts that control loaded clips, but most are all from the loader in the main timeline.  I have a moviclip on the main timeline that I want to make visible or invisible depending on what keyframe is playing in another loaded swf.
    If I try to call the movieClip from the loaded SWF I get "error #1119.  Access of possibly undefined property...." because it doesn't exist in the loaded SWF, just the main timeline. 
    The old AS2 way just used "_root".  Since "_root" doesn't exist any more, how do you control items on the main TimeLine from a loaded SWF?

    I am not clear what you mean because you are saying you are trying to target a movieclip that does not exist where you are trying to target it.
    Try using a trace to see what you are targeting when you you target the MovieClip(parent.parent)....
    trace(MovieClip(parent.parent));
    The other approach I mentioned earlier is the more OOP-correct approach if you would rather try that way.  Here's a rough outline of it...
    AS3 - Dispatch Event
    http://forums.adobe.com/thread/470135?tstart=120
    Example:
    Add something to trigger the event in the child (your loaded swf):
    dispatchEvent(new Event("eventTriggered")); (
    if dispatchEvent problem, see: http://www.kirupa.com/forum/showthread.php?p=1899603#post1899603)
    In your loading/parent swf, listen for the complete event on the Loader.contentLoaderInfo.  In the complete event handler, add a listener for the event on the loaded swf.
    // event handler triggered when external swf is loaded
    function loaderCompleteHandler(event:Event) {
        MovieClip(event.currentTarget.content).addEventListener("eventTriggered", eventHandler);
    function eventHandler(event:Event):void {
        trace("event dispatched in loaded swf");
       // this is where your main file can set the visible property of your movieclip

  • Passing a variable from an mxml component to the main mxml file

    Hey guys,
    I have a popup titlewindowt which is defined as a component in a separate mxml component file.
    In the popup window i have an inputbox and a button
    When i press the button in that popup window i want the text in the input box to be transfered across to a variable in my main mxml file
    How can i do this?
    Thanks
    Chris

    Since you are already tied in to the top level application then I would add a listener at the application level and in the component do a:
      FlexGlobals.topLevelApplication.dispatchEvent(....)
    However, I can't help but encourage you to decouple this functionality and pass events around rather than what you are currently doing.
    There are a few ways you can do this.  One is to use an MVC framework to model your application after.
    A simpler approach even would be to have the component simploy dispatch events to itself and have whatever is creating the component listen for the events and do higher level functionality.
    Good Luck!

  • How to _root in as3 (buttons in movie clip referencing to main timeline)

    Hi, I created buttons within a movie clip that i placed in the main timeline.I am  a novice to as3. I just wanted the button to go to the frame label of the main timeline. i used to do this with _root in the old flash. how do i do this?
    thumb02_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
    function buttonClicked(event:MouseEvent):void
        gotoAndPlay("slide2");

    Thanks for the quick reply!
    somehow i must be doing something wrong though. It's not working...
    I added a stop to the "slide02" labeled section of the main timeline.
    and I also added a stop to the beginning and end of the movieclip. Am I doing something wrong? attached is my file....thanks!!
    stop();
    thumb02_btn.addEventListener(MouseEvent.CLICK, buttonClicked);
    function buttonClicked(event:MouseEvent):void
        MovieClip(this.root).gotoAndPlay("slide2");
    stop();

  • Please help! first website! movie clip placed on main timeline wont play!

    Hi! if any one could please help me it would be greatly
    appreciated!
    So im trying to make my first website in flash and ive ran
    into a problem. I have the main movie, my main time line. I have a
    few animations going on in this that were all created in that main
    time line. those work fine. however, i created two new movie clips
    (still inside the same .fla file) and animated them with thier own
    time line. I then thought you could just drag and drop these movie
    clips onto your main time line and they would play inside the
    movie. but when i press ctrl + enter, the dont play!
    here are some points of intrest.
    my main movie (the main time line) is 130 frames.
    the movie clips i made inside the same .fla file are between
    400 and 600 frames.
    i placed both new movie clips on the 130th frame in the time
    line with their own layers.
    also there is a layer for actions on the 130th that has
    stop();
    i thought that maybe the time line had to be as long as those
    movie clips i created and so i extended it but they still didnt
    play.
    im thinking action script is involved? please help me im
    getting pretty frustrated and im sure there is something simple to
    achieve this.
    here is a link where you can download the source files im
    using. if you open the file the two movie clips i created are
    called front two and front one and are layers with the same name.
    this board wont let me fully post my link cause the last word
    in it is s*h*i*t* so youll have to type it in your browser. its
    http://public.me.com/matts*h*i*t*
    (just remove the asterisks)
    also i noticed that my file is huge. i used photoshop to
    create everything and them imported it into flash. is there a way i
    can reduce this size?
    thank you sooo much! please help!
    -Matt

    Hey Matt,
    I'll take a look at your file, but as a general rule, a
    movieclip's timeline plays automatically when it is first
    instantiated. Instatiated means its first frame where "it exists"
    on the timeline that contains it. So the layer that holds your
    movieclip animation, needs to extend the length of the timeline you
    want that movieclip to "exist". Other than that rule, the frames
    don't NEED to match the frames inside said movieclip.
    So, if movieclips play automatically, and yours isn't, there
    must be something either stopping the movieclips timeline, or your
    movieclip isn't existing on the timeline because the layer that
    holds it, doesn't have keyframes the length you need it to.
    Yeah optimizing your sprites (2d graphical elements), and
    using vector when you need to (if you don't know the difference
    between raster and vector, google it) will significantly lower your
    outputted .swf file size.
    Edit: After looking at your file, your movieclips are not
    playing (well, they're technically playing, just not showing up)
    because your masker layer has multiple objects on it. A masker
    layer (not to be confused with the maskee layer, the layer being
    masked) needs to have only one object on it, or else you break the
    mask. The grey border of your mask movieclip needs to be deleted
    before your animation will play.

  • Convert a movie clip back to the main timeline? Help!

    I hope you guys can help me with this because this is a work project. Here's the situation:
    The entire .fla animation consists of nothing but two really long movie clips. Which are placed on frames 1 and 2 of the main timeline. Now for reasons that are too deep for me to go into explaination about my boss is telling me that I have to have everything main timeline -no movie clips. I've tried copypasting all of the frames but they all paste wayyy to large on the main timeline and they wind up in different places on the stage.
    How can I move all of the frames from my two movie clips onto the main timeline without everything breaking? Better yet - is there any way to just convert a movie clip into an .fla?

    you're on the right track.  note the x,y of your movieclip in frame 1.  create a new layer and paste all the frame 1 movieclip's frames into that new layer.  click the edit multiple frames icon below your timeline.  select all the frames, click an on-stage object.  in the properties panel, change the x,y of the all the selected objects to the previously noted values

  • Load a MC on the main timeline from a MC.     AS3

    I have a movie clip (mc_menu) on that is on the main timeline.
    This movie clip has buttons that I want to use to display other movie clips on the main (parent) timeline.

    Start here:
    http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9 b90204-7e4e.html

  • How do I use a variable to set movie clip properties?

    I'm building a simple contact page that allows users to
    select a city from a comboBox. I'd like to pass the selected
    comboBox data through a variable that controls a movie clip with
    the same name. (already on the stage)
    locationListener.change = function (loc_obj:Object) {
    var loc_mc = loc_obj.target.selectedItem.data;
    loc_mc._visible = true;
    So far this hasn't worked. I've tested hardcoding the movie
    clip instance name (Atlanta._visible = true) and it works, but I
    can't figure out why using the variable loc_mc won't trigger
    interaction with the movie clip.
    Something simple, I assume. Thanks in advance for any
    help.

    clbeech:
    I tried using your suggestion, but for some reason it doesn't
    recognize it as naming the movie clip instance. I traced the
    variable and confirmed that the correct value (Atlanta) is being
    passed.
    I assume this is because the variable is not declared as a
    MovieClip, but I can't figure out how to convert it inside the
    function.

  • I need to delete a variable containing a movie clip class and recreate it with a different movie clip class

    Hello,
    I am creating a program that is going to help students learn to read. In my project are pages of text with each word having a button that when pressed will display a movieclip presentation about that word (its pronounciation and spelling etc..). In the project I am working on now I have over 450 unique presentations of words to deal with. I don't want to have all of these hundreds of movie clips on the stage and tell them one at a time to stop and rewind and then have one play each time a word button is pressed. That seems to be very inefficient to me. So I want to do this with some code in Actionscript 3.
    I know I can dynamically add movieclips to the stage using addChild(movieclipname) and remove them using removeChild(movieclipname) but there is a problem. I have hundreds of unique movieclips and I don't want to have to manage hundreds of variables containing the indivudual movieclip instancess. It is a real pain having to figure out what instance is still on the stage before i delete it.
    In Adobe Director all I have to do is this:
    on mousedown me
         sprite(me.spritenum).member = member("somenewmember:)
    end
    and that was it
    But if I do this in actionscript 3:
    removeChild(some_mc)
    some_mc still exists in memory. And I have to know exactly what variable it is to remove or else the movie will fail with an error. If I try to be brutish about it and try to implicitly remove all 450 movieclip instance variables from the stage I will get at least 449 errors.
    What I want to do is this:
    removeChild(some_mc)
    some_mc = void //or //delete some_mc
    var some_mc:MovieClip = new someother_mc();
    addChild(some_mc)
    but this doesn't work
    How am I going to remove one of 450 movie clips and add a new totally different movie clip without the code knowing exactly what the last movie clip was? I suppose if could remove a child from the stage based on a string name then I could hold that name in a variable for later disposal.Can I do this?
    Thanks for any help you can give me. I am new to actionscript.

    Hey I think I may have a solution:
    //begin code
    var myMC:MovieClip = new ball();
    var starMC:MovieClip = new star();
    var youpresseeditMC:MovieClip = new youpresseedit();
    starMC.name = "star";
    myMC.name = "ball";
    youpresseeditMC.name = "youpresseedit"
    addChild(myMC);
    box.addEventListener(MouseEvent.MOUSE_DOWN, replaceball);
    press_BTN.addEventListener(MouseEvent.MOUSE_DOWN, replaceballwithtext);
    function replaceball(event:MouseEvent):void {
        trace(myMC.name)
        removeChild(myMC);
        myMC = starMC;
        addChild(myMC);
        trace(myMC.name)
    function replaceballwithtext(event:MouseEvent):void {
        trace(myMC.name)
        removeChild(myMC);
        myMC = youpresseeditMC;
        addChild(myMC);
        trace(myMC.name)
    ///end code
    This works. I see the ball object replaced  by the star and I am able to do this by manipulating just myMC. Is there anything I should be concerned with in this approach?
    Thanks for your help

  • How to pass a variable from HTML to Flash

    I have built my flash ad banner in Flash 9 and now want the
    HTML code to pass the url over to the flash movie that it should
    jump to when clicked.
    The info in the help file seems out of date for the latest
    HTML template as it uses mainly JavaScript to get round IE's
    dreadful embeding issue. So my problem is, how do I pass a variable
    from the HTML to the actionScript specified int he Help file
    (running on a full screen button) as shown below?
    myButton_btn.onRelease = function() {
    if (clickTAG.substr(0, 5) == "http:") {
    getURL(clickTAG);
    via the html code now used by Flash 9 which is like this:
    <!-- saved from url=(0013)about:internet -->
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <title>Advert_long</title>
    <script language="javascript"> AC_FL_RunContent = 0;
    </script>
    <script language="javascript"> DetectFlashVer = 0;
    </script>
    <script src="AC_RunActiveContent.js"
    language="javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    // Globals
    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Revision of Flash required
    var requiredRevision = 115;
    // -->
    </script>
    </head>
    <body bgcolor="#ffffff">
    <!--url's used in the movie-->
    <!--text used in the movie-->
    <!--
    Coping
    with
    Growing
    Audio
    Series
    Theraputic stories
    for children aged
    4 to 9
    -->
    <script language="JavaScript" type="text/javascript">
    <!--
    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
    alert("This page requires AC_RunActiveContent.js.");
    } else {
    var hasRightVersion = DetectFlashVer(requiredMajorVersion,
    requiredMinorVersion, requiredRevision);
    if(hasRightVersion) { // if we've detected an acceptable
    version
    // embed the flash movie
    AC_FL_RunContent(
    'codebase', '
    http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
    'width', '120',
    'height', '600',
    'src', 'Advert_long',
    'quality', 'high',
    'pluginspage', '
    http://www.macromedia.com/go/getflashplayer',
    'align', 'middle',
    'play', 'true',
    'loop', 'true',
    'scale', 'showall',
    'wmode', 'window',
    'devicefont', 'false',
    'id', 'Advert_long',
    'bgcolor', '#ffffff',
    'name', 'Advert_long',
    'menu', 'true',
    'allowScriptAccess','sameDomain',
    'allowFullScreen','false',
    'movie', 'Advert_long',
    'salign', ''
    ); //end AC code
    } else { // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be
    placed here.'
    + 'This content requires the Adobe Flash Player.'
    + '<a href=http://www.macromedia.com/go/getflash/>Get
    Flash</a>';
    document.write(alternateContent); // insert non-flash content
    // -->
    </script>
    <noscript>
    // Provide alternate content for browsers that do not support
    scripting
    // or for those that have scripting disabled.
    Alternate HTML content should be placed here. This content
    requires the Adobe Flash Player.
    <a href="
    http://www.macromedia.com/go/getflash/">Get
    Flash</a>
    </noscript>
    </body>
    </html>

    You should use SWFObject to embed your Flash. Not only does
    it make
    embedding more straightforward, it makes passing query
    parameters very easy.
    Check out:
    http://code.google.com/p/swfobject/
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • How to pass a variable from HTML to Flash 9

    I have built my flash ad banner in Flash 9 and now want the
    HTML code to pass the url over to the flash movie that it should
    jump to when clicked.
    The info in the help file seems out of date for the latest
    HTML template as it uses mainly JavaScript to get round IE's
    dreadful embeding issue. So my problem is, how do I pass a variable
    from the HTML to the actionScript specified int he Help file
    (running on a full screen button) as shown below?
    myButton_btn.onRelease = function() {
    if (clickTAG.substr(0, 5) == "http:") {
    getURL(clickTAG);
    via the html code now used by Flash 9 which is like this:
    <!-- saved from url=(0013)about:internet -->
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1" />
    <title>Advert_long</title>
    <script language="javascript"> AC_FL_RunContent = 0;
    </script>
    <script language="javascript"> DetectFlashVer = 0;
    </script>
    <script src="AC_RunActiveContent.js"
    language="javascript"></script>
    <script language="JavaScript" type="text/javascript">
    <!--
    // Globals
    // Major version of Flash required
    var requiredMajorVersion = 9;
    // Minor version of Flash required
    var requiredMinorVersion = 0;
    // Revision of Flash required
    var requiredRevision = 115;
    // -->
    </script>
    </head>
    <body bgcolor="#ffffff">
    <!--url's used in the movie-->
    <!--text used in the movie-->
    <!--
    Coping
    with
    Growing
    Audio
    Series
    Theraputic stories
    for children aged
    4 to 9
    -->
    <script language="JavaScript" type="text/javascript">
    <!--
    if (AC_FL_RunContent == 0 || DetectFlashVer == 0) {
    alert("This page requires AC_RunActiveContent.js.");
    } else {
    var hasRightVersion = DetectFlashVer(requiredMajorVersion,
    requiredMinorVersion, requiredRevision);
    if(hasRightVersion) { // if we've detected an acceptable
    version
    // embed the flash movie
    AC_FL_RunContent(
    'codebase', '
    http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
    'width', '120',
    'height', '600',
    'src', 'Advert_long',
    'quality', 'high',
    'pluginspage', '
    http://www.macromedia.com/go/getflashplayer',
    'align', 'middle',
    'play', 'true',
    'loop', 'true',
    'scale', 'showall',
    'wmode', 'window',
    'devicefont', 'false',
    'id', 'Advert_long',
    'bgcolor', '#ffffff',
    'name', 'Advert_long',
    'menu', 'true',
    'allowScriptAccess','sameDomain',
    'allowFullScreen','false',
    'movie', 'Advert_long',
    'salign', ''
    ); //end AC code
    } else { // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be
    placed here.'
    + 'This content requires the Adobe Flash Player.'
    + '<a href=http://www.macromedia.com/go/getflash/>Get
    Flash</a>';
    document.write(alternateContent); // insert non-flash
    content
    // -->
    </script>
    <noscript>
    // Provide alternate content for browsers that do not
    support scripting
    // or for those that have scripting disabled.
    Alternate HTML content should be placed here. This content
    requires the Adobe Flash Player.
    <a href="
    http://www.macromedia.com/go/getflash/">Get
    Flash</a>
    </noscript>
    </body>
    </html>

    You should use SWFObject to embed your Flash. Not only does
    it make
    embedding more straightforward, it makes passing query
    parameters very easy.
    Check out:
    http://code.google.com/p/swfobject/
    Dave -
    www.offroadfire.com
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • How load variables to a movie clip on a masked layer on my main time line

    the problem I have is that I been trying to load text from a
    text file news.txt into a movie clip on my main time line the
    problem is when the layer where the video clip is locates is masked
    the variables will not load, but it does work when the layer is
    unmasked, but then the website does not work the way it is suposed
    to look.
    any Idea on how I can get arround this????

    PArt of the problem will be due to declaring the uiLoader inside of a function.  When you do that you limit its scope to within that function.  You should declare it outside of any function if you need to access it in more than one function.
    import flash.events.MouseEvent;
    import fl.motion.MotionEvent;
    var uiLoader:UILoader;
    var targetObj:Object;
    The other problems I see regard the line you point to.  It is not spelling the name the same, using a lowercase "l". Also, if you want to target what the UILoader contains, you should target its "content" property, as in...
    targetObj = uiLoader.content.mask_01

  • LoadVars-using send to pass a variable from flash to php

    For the life of me, I've tried everything:
    I've researched LoadVars on Adobe forum, used David Powers'
    books, googled 'flash to php', LoadVars, etc. and tried
    sendAndLoad, send, and using $_POST, $_GET, $_REQUEST.
    $HTTP_POSTVARS but I keep getting this same error. any advice
    please?
    I have a Unix server running Apache/PHP 4 - LoadVars worked
    to load name-value pairs into an array -see thread)
    My goal with this simple app is to prototype being able to
    pass a variable from flash to a variable in php.
    Parse error: syntax error, unexpected T_VARIABLE in
    flash_to_SQL.php on line 5
    Actionscript 2.0 code:
    var c :LoadVars = new LoadVars();
    c.testing = "123FOUR";
    c.send ("
    http://127.0.0.1/flash_to_SQL.php","_self","POST");
    php code: (I also tried $_POST, $_GET, $_REQUEST.
    $HTTP_POSTVARS)
    <?php
    //mysql 4.1.2, php 4 , NO mysqli
    ecbo $_REQUEST ['testing'];
    /?>

    var formData:LoadVars = new LoadVars();
    formData.fname = "Name";
    formData.send("
    http://www.website.com/flash_php.php",
    formData, "POST");
    <?php
    $name = $_POST['fname'];
    echo $name;
    ?>

  • How to pass a variable from one class to another class?

    Hi,
    Is it possible to pass a variable from one class to another? For e.g., I need the value of int a for calculation purpose in method doB() but I get an error <identifier> expected. What does the error mean? I know, it's a very, very simple question but once I learn this, I promise to remember it forever. Thank you.
    class A {
      int a;
      int doA() {
          a = a + 1;
          return a;
    class B {
      int b;
      A r = new A();
      r.a;  // error: <identifier> expected. What does that mean ?
      int doB() {
         int c = b/a;  // error: operator / cannot be applied to a
    }Thank you!

    elaine_g wrote:
    I am wondering why does (r.a) give an error outside the method? What's the reason it only works when used inside the (b/r.a) maths function? This is illegal syntax:
    class B {
      int b;
      A r = new A();
      r.a;  //syntax error
    }Why? Class definition restricts what you can define within a class to a few things:
    class X {
        Y y = new Y(); //defining a field -- okay
        public X() { //defining a constructor -- okay
        void f() { //defining a method -- okay
    }... and a few other things, but you can't just write "r.a" there. It also makes no sense -- that expression by itself just accesses a field and does nothing with it -- why bother?
    This is also illegal syntax:
    int doB() {
          A r = new A();
          r.a;  // error: not a statement
    }Again, all "r.a" does on its own is access a field and do nothing with it -- a "noop". Since it has no effect, writing this indicates confusion on the part of the coder, so it classified as a syntax error. There is no reason to write that.

Maybe you are looking for

  • Replication of Custom Include IS-U to CRM

    Hello gents! CRM 4.0 WebClient, IS-U 4.72. Currently custom fields where added to the technical objects in ISU. I am currently facing the following problem. A custom include was added into the IFLOT table (Functional Location) in IS-U. It appears on

  • Issue with display of view attributes via page personalization

    Hi, We are having the standard search region whose VO we are extending to display additional columns. For this we did VO Ext, migrated the code to the instance. We added new columns in the 'Result Region' via personalization and mapped the correspond

  • How to create Dynamic Table with more than one column?

    Hi, I'm trying to learn Dreamweaver. I'm trying to display 2 units from my database in the same row then I would like go to next row. By default DW shows single record in each row. Is it possible to display more than one? Thank you

  • HU Number determination

    Hi, In my program every time I need to create idoc and I need to create handling unit number. I am calling standard idoc so inside of idoc only the function module ‘HU_PACKING_CREATE’ is there to create the handling unit number. For this I need to gi

  • Special offers for UK/European users at Creative's Online St

    Hi folks, I was just looking at the UK/European store and I store some special offers in the accessory section. Just thought I'd let the relevants users know in case it was helpful: <Zen Micro Special Offers - <EM>for a limited time only</EM> - Two Z