dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Reference Parameter Passing: What am i passing?

  1. #1
    Senior Member
    Join Date
    Aug 2001
    Posts
    227

    [RESOLVED] Reference Parameter Passing: What am i passing?

    Ok, hope this makes sense.

    If you declare 2 objects, object A & B. If you then Define object A and pass Object B as a reference (even though B is not initiated), what are you passing? Null? I always thought i was passing the reference to that object, and not the objects value.

    For example.

    Below works fine. I am passing "imageInfo" as a parameter into the constructor of "layoutEventManager". It works fine because imageInfo is already defined, and therefor causes no problems.
    Code:
    			this.imageInfo = new ImageInterativeInfo( this.eventImageInfoLoaded );
    			this.layoutEventManager = new LayoutEventManager( this.slideShow, this.thumbnailGallery, this.imageInfo );
    Below causes an error, saying i cannot access a property or method of a null object.
    Code:
    			this.layoutEventManager = new LayoutEventManager( this.slideShow, this.thumbnailGallery, this.imageInfo );
    			this.imageInfo = new ImageInterativeInfo( this.eventImageInfoLoaded );

    Now you'd probably say that "imageInfo" is being used before it is defined, when that is not the case. I have checked the timeline and it is not used until far down the timeline. Infact, i am so sure of this because simply put, only one line in one function even uses "imageInfo", and the rest of the class is empty. The only thing that uses imageinfo ofcourse, on the constructor, is to write the reference to an objects in the layouteventmanager.


    So, what exactly am i passing? I always thought if you passed B to A before B was defined, that you were passing a reference to the property B, and not B's value. Which would mean that when you Define B, A's reference of B would also be defined.

    Any thoughts? (the only thing that uses imageInfo btw, is a eventlistener.. maybe that has .. anything to do with it?)
    Last edited by Zeusbwr; 10-15-2006 at 11:54 PM.

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    A property is width, x etc. You are passing its value. If you do the same in AS2 you don't get an error but the parameter passed would be undefined.
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  3. #3
    Senior Member
    Join Date
    Aug 2001
    Posts
    227
    So you are passing a reference to the value and not the declared variable? (if that makes sense)

  4. #4
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,448
    In former flash versions when you write a function with a parameter for an object, which is not yet on stage, but in the main timeline, it will be undefined. An object has to be physically present, when referred to it or it does not exist for the Player (null in AS3 for a variable).
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

  5. #5
    Actionscript Developer KigD's Avatar
    Join Date
    Jan 2003
    Location
    georgia
    Posts
    597
    AS is more similar to java than C++ in this respect. In C++ you can send reference parameters which will actually send the physical variable. In java (and flash), sending a variable is sending the value.

    -Danny
    K2xL - My games, tutorials, message boards, and experiments.
    Blog

  6. #6
    Senior Member
    Join Date
    Aug 2001
    Posts
    227
    k thanks guys

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