Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-13-2012, 01:19 AM   #1
WarKirby
Senior Member
 
Join Date: May 2011
Posts: 283
Default Updating a reference?

Hi everyone. it feels like this question should be easy, but i'm sure i'm misunderstanding something.

To explain my situation loosely, i have an object (bb) which is created by the timeline (by switching its parent object to an appropriate frame). The object is actually named "bb" in the timeline, and it's parent has a variable named "bb", so this causes the variable to be automatically populated with a reference to that object.

by the way, i have disabled the setting "Automatically declare stage instances"

farther to the above, a reference also exists in an array somewhere, which is extremely important. i assigned it something like this:
myarray[0] = [container, container.bb, this]

note that the object calling this code is another child of bb's parent (it is a sibling of bb). the parent being "container"

Ok is all that clear?


Now what i actually want to do, and need help understanding, is how things behave when all this is updated. I want to alter some frames on the timeline of the container (at authortime) to contain a different instance of the bb object. The new instance will have different dimensions but the same name, and the old bb will not be on that frame, so there will only be one instance of bb at a time.

What will happen if i do this? will the container's bb variable be automatically populated with the new reference when it switches frames? Will the reference in myArray also be updated?
WarKirby is offline   Reply With Quote
Old 07-13-2012, 05:20 AM   #2
Sonny
Senior Member
 
Join Date: Aug 2010
Location: Sydney,Australia
Posts: 132
Default

What does the container.bb refer to?
It refers to a variable bb that exists on the current frame the play head is in for that movie clip. If you have a movieclip on that stage which has a instance name bb then it refers to that object . So from the container if you call this["bb"] that refers to a variable bb . It may or may not exists in that class.

Quote:
Now what i actually want to do, and need help understanding, is how things behave when all this is updated. I want to alter some frames on the timeline of the container (at authortime) to contain a different instance of the bb object. The new instance will have different dimensions but the same name, and the old bb will not be on that frame, so there will only be one instance of bb at a time.
That being said if you have a container movie clip which has 4 frames. Each frame has a movie clip named bb. Now this is the same as programatically creating a new movie clip and adding it to the display list on each frame.
So a simple code like this :
ActionScript Code:
btn.addEventListener(MouseEvent.MOUSE_DOWN,handleMouse); function handleMouse(e:MouseEvent){        var currentbb = container.bb; //If bb exists current bb is set to that instance     container.bb["testValue"] = "something"; //if bb exists a dyn value is created     trace("Parameters " + container.bb.x); // 8     container.bb.x += 40;        trace("Parameters " + container.bb.x+" testing current value " + container.bb["testValue"] );//works 48 , "something"     container.nextFrame();//whatever changes you made before on bb is lost here     trace("Parameters " + container.bb.x+" testing current value " + container.bb["testValue"] ); ////prints 92 and undefined         trace(currentbb == container.bb); //Prints false.this still holds reference to the old bb .         trace(currentbb["testValue"]); //Proof:: Prints something           }
will work .as in bb wont be undefined as long as a movie clip exists on the stage on that frame. But then again if you set a variable on the container.bb on one particular frame .go to someother frame where bb is a new movieclip .. the variable you have declared is lost.


Hope that clarifies it a little bit .

Last edited by Sonny; 07-13-2012 at 05:26 AM.
Sonny is offline   Reply With Quote
Old 07-13-2012, 07:57 AM   #3
WarKirby
Senior Member
 
Join Date: May 2011
Posts: 283
Default

Quote:
Originally Posted by Sonny View Post
will work .as in bb wont be undefined as long as a movie clip exists on the stage on that frame. But then again if you set a variable on the container.bb on one particular frame .go to someother frame where bb is a new movieclip .. the variable you have declared is lost.


Hope that clarifies it a little bit .
umm, no, not really


ok can we break it down:

Quote:
will work .as in bb wont be undefined as long as a movie clip exists on the stage on that frame.
ok, on frame 0 (a keyframe) of the container, i have an instance of my BoundingBox class named "bb". it is 10x10 pixels. this automatically populates into container.bb perfectly.

on frame 1, i insert a blank keyframe, i drag another instance of my BoundingBox class from the library and onto frame 1. I name it "bb" and give it dimensions of 10x20 pixels



so at runtime, if i do container.goToAndStop(1) then what happens to the property container.bb ? Is it any of these?

a. It contains a reference to the new 10x20 instance
b. it contains null, undefined, or some other nonuseful value
WarKirby is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:22 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.