A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: accessibilty of instances in different frames

  1. #1
    THE YELLOW FLASH!
    Join Date
    Feb 2008
    Posts
    57

    accessibilty of instances in different frames

    I need some help with the AS3 core concept here.In AS2,suppose there is an input text field in frame 1 with var name ONE,its text content can be accessed in say frame 2 even though that textfield is not in stage.

    But in AS3,I think this is not possible right?So,how can I access instances or movieclips or variables at different frames?Do I have to make a class and make const vars?If so,If I have some irregular shape,say a man as movieclip,how can I add it to the global class?

    Else,copying the instances in all the frames and making its visibility true or false according to need,the only solution?

    Please help,am currently migrating from AS2 to AS3.

    Thank u
    The CodeBreaker!

  2. #2
    THE YELLOW FLASH!
    Join Date
    Feb 2008
    Posts
    57
    No one knows the basic concept of AS3????
    The CodeBreaker!

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I have no idea how it worked or didn't work in as2, but in as3 (or rather, avm2), instances from other frames do not exist. That is, they've either been removed and destroyed, or they haven't been created yet.

    You can manage them in memory yourself, by assigning them to variables or properties of the document class or other persistent instance and accessing them through that.

    What does a shape have to do with frames? and what does your question about instances on different frames have to do with adding a shape to "the global class"? What do you mean by "the global class", and what would adding a shape to a class mean?

  4. #4
    THE YELLOW FLASH!
    Join Date
    Feb 2008
    Posts
    57
    Ok, I will explain things a little more clearly.
    For example,suppose, I have 2 frames in my timeline.


    #1 = An input text box with instance name 'mc'
    #2 = A dynmaic text box with instance name 'kk'




    Both frames have 'stop()' in it.Just for now,I use the rightClick>Forward to goto next frame(because I made this to explain my problem,so dint add button).

    On Frame #2 there is this AS
    Actionscript Code:
    mc.text = kk.text

    And when I run this,I get this error




    Whereas in AS2,this error doesnt occur.

    By making them global,what I meant is that making them static var,like I read from this site.
    Actionscript Code:
    package com.greenethumb.utils
    {
        public class GlobalVarContainer
        {
            public static var vars:Object = {};
        }
    }

    But,If I have to draw a human and name it as 'Human',I cannot give
    Actionscript Code:
    public static var hum:MovieClip = new MovieClip()
    right?Because its already defined in stage.

    The basic problem is that,I want to know is there any way I can refer to MovieClips,text boxes,variables at different frames in timeline from other frame?

    BtW, Thanks for the reply 5Tons ...
    Sorry for noob questions...am just picking up AS3 concepts ...
    The CodeBreaker!

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    There's no need to make a "Global" class to hold them as static variables. All you have to do is keep a reference to the objects so that you can refer to them after Flash clears away the properties it auto-added for you.

    Here's what happens when the playhead moves from one frame to another. Flash removes all instances which are not on the new frame, and un-sets the properties it dynamically added for you. Then, it creates and adds the new instances, and sets properties for you to refer to them. The reason you cannot refer to something which was on the first frame from code in the second frame is that the thing which was on the first frame no longer exists. You cannot have a face-to-face conversation with Shakespeare, because he's not around anymore. But you can go see Stratford-upon-Avon because it is still there.
    To keep things around, you have to keep a reference to them somewhere. You can do this by creating a variable or property in your document class, since your document class exists throughout all frames.
    So, if you'd put on the first frame:
    Code:
    this.mcref = mc;
    It would create a property mcref that will point to the same instance that mc points to, and will continue to point to it even after mc no longer does.
    But, instead of relying on an untyped dynamic property, you could actually declare a variable in your document class and set that.

    That helps you keep things around. But you still can't refer to things before they exist. And if you happen to go back from frame 2 to frame 1, you'll get a NEW mc that is not the same mc you had the first time through.

    The problem is that you seem to be using frames for state. Frames are not for state. Frames are for animation.

    What you should probably be doing is creating a real class to handle your logic, and putting things on and off the display yourself.
    If you must use frames and IDE placed assets, then at least initialize them from persistent data that you manage properly.

  6. #6
    THE YELLOW FLASH!
    Join Date
    Feb 2008
    Posts
    57
    oh...Thanks a lot 5Tons
    I got it.Yea I use frames for states,because am not that much into animation using codes.Guess I have to learn any of the open source tweeners.That will do the animation,instead of using the frames
    Let me resume my experiments with AS3.Will be here if I have more doubt Thanks for helping...
    The CodeBreaker!

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