Skip to main content
Known Participant
September 29, 2006
Question

Passing values from mc to mc/instance to instance

  • September 29, 2006
  • 72 replies
  • 3385 views
Ive made a new topic for this cos the last one went wildly off-topic...

Im trying to use info from the soldier instance to set up bullets he fires.
Each new bullet wants to be its own instance/mc whatever. Thing is that I cant get the info out of _root.soldier and into _root.bulletX (where X is an arbitary value)

there is code in the bullet onClipEvent(load) like
this._rotation = soldier1._rotation;
Which by the looks of some traces Ive done just gives soldier._rotation as undefined.

How can I pass a value out of soldier to use here?
This topic has been closed for replies.

72 replies

Inspiring
October 4, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efv0e9$j45$1@forums.macromedia.com...
> hey thanks for the help and especially the
> trace(this);
> trace(this._parent);
> code. thats some useful stuff I didnt know you could do that.

Welcome. For future reference you should reply to your original post.


Known Participant
October 4, 2006
hey thanks for the help and especially the
trace(this);
trace(this._parent);
code. thats some useful stuff I didnt know you could do that.
Inspiring
October 1, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efkdr8$95f$1@forums.macromedia.com...
> does _parent refer to the mc that "gave birth" to the new instance?

if you are using duplicateMovieClip, then the _parent is the same for all
duplicated bullets... the holder of the original bullet. So, if the bullet
instance is inside of your soldier1 MC then the _parent of each duplicated
bullet will be the soldier1.

> so if duplicateMoveClip(..."bullet"...) is in soldier1 will the _parent of
> bullet be soldier1? or will it be the original bullet Im duplicating?
>
> Also my traces threw up odd results. I got the rotation to work but not
> the
> _x and _y positions. Odd.

What are the outputs of your 'odd results'... if _x and _y don't work, TRACE
'em.

trace(this._parent._x);
trace(this._parent._y);

> I think I might start using proper .as scripts and define everything as
> classes cos this is getting too confusing using mc instances with code
> inside
> them.
>

This is my preferred way to go.



Inspiring
October 1, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efk7gi$2f1$1@forums.macromedia.com...
> hmm afraid that the kind of code I was using. The problem is you cant
> take a
> variable out of one instance and use it in another.
>
> I know that soldier1._rotation is working cos it work for soldier clip.
>
> The problem comes when you want to pass soldier1._rotation onto the bullet
> cos
> a statement like
>
> bullet._rotation = soldier1._rotation;
>
> within the code for the bullet will simply decide that it cant find
> soldier1._rotation. What I think I need is a way to make the value public
>

okay, here is what you want to check (for this case and any case when you
have some issue like this --- unexpected behavior)

TRACE, TRACE, TRACE.

Each bullet is coming from an attachMovie or a duplicateMovieClip, right???

In either case, in your code you have:

onClipEvent(load) {
this._rotation = solder1._rotation;
}

which is a valid statment. This says, find the rotation value of soldier1
and assign it to this (the Bullet clip)

So, TRACE...
add
trace(soldier1._rotation);
to the onClipEvent(load) handler above. You see that soldier1._rotation is
undefined.

next add another TRACE...
add
trace(this);
to the handler.

You will see that 'this' is referring to your bullet. But, soldier1 is not
in the bullet instance, it is in the _parent instance (most likely - depends
on your setup) so, you should try

onClipEvent(load) {
this._rotation = _parent.soldier1._rotation;
}

if that doesn't work, add the following traces and post their output

trace(this);
trace(this._parent);






Ive made a new topic for this cos the last one went wildly off-topic...

Im trying to use info from the soldier instance to set up bullets he fires.
Each new bullet wants to be its own instance/mc whatever. Thing is that I
cant get the info out of _root.soldier and into _root.bulletX (where X is an
arbitary value)

there is code in the bullet onClipEvent(load) like
this._rotation = soldier1._rotation;
Which by the looks of some traces Ive done just gives soldier._rotation as
undefined.

How can I pass a value out of soldier to use here?


Inspiring
October 1, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efkdr8$95f$1@forums.macromedia.com...
> does _parent refer to the mc that "gave birth" to the new instance?

if you are using duplicateMovieClip, then the _parent is the same for all
duplicated bullets... the holder of the original bullet. So, if the bullet
instance is inside of your soldier1 MC then the _parent of each duplicated
bullet will be the soldier1.

> so if duplicateMoveClip(..."bullet"...) is in soldier1 will the _parent of
> bullet be soldier1? or will it be the original bullet Im duplicating?
>
> Also my traces threw up odd results. I got the rotation to work but not
> the
> _x and _y positions. Odd.

What are the outputs of your 'odd results'... if _x and _y don't work, TRACE
'em.

trace(this._parent._x);
trace(this._parent._y);

> I think I might start using proper .as scripts and define everything as
> classes cos this is getting too confusing using mc instances with code
> inside
> them.
>

This is my preferred way to go.



Inspiring
October 1, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efk7gi$2f1$1@forums.macromedia.com...
> hmm afraid that the kind of code I was using. The problem is you cant
> take a
> variable out of one instance and use it in another.
>
> I know that soldier1._rotation is working cos it work for soldier clip.
>
> The problem comes when you want to pass soldier1._rotation onto the bullet
> cos
> a statement like
>
> bullet._rotation = soldier1._rotation;
>
> within the code for the bullet will simply decide that it cant find
> soldier1._rotation. What I think I need is a way to make the value public
>

okay, here is what you want to check (for this case and any case when you
have some issue like this --- unexpected behavior)

TRACE, TRACE, TRACE.

Each bullet is coming from an attachMovie or a duplicateMovieClip, right???

In either case, in your code you have:

onClipEvent(load) {
this._rotation = solder1._rotation;
}

which is a valid statment. This says, find the rotation value of soldier1
and assign it to this (the Bullet clip)

So, TRACE...
add
trace(soldier1._rotation);
to the onClipEvent(load) handler above. You see that soldier1._rotation is
undefined.

next add another TRACE...
add
trace(this);
to the handler.

You will see that 'this' is referring to your bullet. But, soldier1 is not
in the bullet instance, it is in the _parent instance (most likely - depends
on your setup) so, you should try

onClipEvent(load) {
this._rotation = _parent.soldier1._rotation;
}

if that doesn't work, add the following traces and post their output

trace(this);
trace(this._parent);






Ive made a new topic for this cos the last one went wildly off-topic...

Im trying to use info from the soldier instance to set up bullets he fires.
Each new bullet wants to be its own instance/mc whatever. Thing is that I
cant get the info out of _root.soldier and into _root.bulletX (where X is an
arbitary value)

there is code in the bullet onClipEvent(load) like
this._rotation = soldier1._rotation;
Which by the looks of some traces Ive done just gives soldier._rotation as
undefined.

How can I pass a value out of soldier to use here?


Inspiring
October 1, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efkdr8$95f$1@forums.macromedia.com...
> does _parent refer to the mc that "gave birth" to the new instance?

if you are using duplicateMovieClip, then the _parent is the same for all
duplicated bullets... the holder of the original bullet. So, if the bullet
instance is inside of your soldier1 MC then the _parent of each duplicated
bullet will be the soldier1.

> so if duplicateMoveClip(..."bullet"...) is in soldier1 will the _parent of
> bullet be soldier1? or will it be the original bullet Im duplicating?
>
> Also my traces threw up odd results. I got the rotation to work but not
> the
> _x and _y positions. Odd.

What are the outputs of your 'odd results'... if _x and _y don't work, TRACE
'em.

trace(this._parent._x);
trace(this._parent._y);

> I think I might start using proper .as scripts and define everything as
> classes cos this is getting too confusing using mc instances with code
> inside
> them.
>

This is my preferred way to go.



Inspiring
October 1, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efk7gi$2f1$1@forums.macromedia.com...
> hmm afraid that the kind of code I was using. The problem is you cant
> take a
> variable out of one instance and use it in another.
>
> I know that soldier1._rotation is working cos it work for soldier clip.
>
> The problem comes when you want to pass soldier1._rotation onto the bullet
> cos
> a statement like
>
> bullet._rotation = soldier1._rotation;
>
> within the code for the bullet will simply decide that it cant find
> soldier1._rotation. What I think I need is a way to make the value public
>

okay, here is what you want to check (for this case and any case when you
have some issue like this --- unexpected behavior)

TRACE, TRACE, TRACE.

Each bullet is coming from an attachMovie or a duplicateMovieClip, right???

In either case, in your code you have:

onClipEvent(load) {
this._rotation = solder1._rotation;
}

which is a valid statment. This says, find the rotation value of soldier1
and assign it to this (the Bullet clip)

So, TRACE...
add
trace(soldier1._rotation);
to the onClipEvent(load) handler above. You see that soldier1._rotation is
undefined.

next add another TRACE...
add
trace(this);
to the handler.

You will see that 'this' is referring to your bullet. But, soldier1 is not
in the bullet instance, it is in the _parent instance (most likely - depends
on your setup) so, you should try

onClipEvent(load) {
this._rotation = _parent.soldier1._rotation;
}

if that doesn't work, add the following traces and post their output

trace(this);
trace(this._parent);






Ive made a new topic for this cos the last one went wildly off-topic...

Im trying to use info from the soldier instance to set up bullets he fires.
Each new bullet wants to be its own instance/mc whatever. Thing is that I
cant get the info out of _root.soldier and into _root.bulletX (where X is an
arbitary value)

there is code in the bullet onClipEvent(load) like
this._rotation = soldier1._rotation;
Which by the looks of some traces Ive done just gives soldier._rotation as
undefined.

How can I pass a value out of soldier to use here?


Inspiring
September 30, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efkdr8$95f$1@forums.macromedia.com...
> does _parent refer to the mc that "gave birth" to the new instance?

if you are using duplicateMovieClip, then the _parent is the same for all
duplicated bullets... the holder of the original bullet. So, if the bullet
instance is inside of your soldier1 MC then the _parent of each duplicated
bullet will be the soldier1.

> so if duplicateMoveClip(..."bullet"...) is in soldier1 will the _parent of
> bullet be soldier1? or will it be the original bullet Im duplicating?
>
> Also my traces threw up odd results. I got the rotation to work but not
> the
> _x and _y positions. Odd.

What are the outputs of your 'odd results'... if _x and _y don't work, TRACE
'em.

trace(this._parent._x);
trace(this._parent._y);

> I think I might start using proper .as scripts and define everything as
> classes cos this is getting too confusing using mc instances with code
> inside
> them.
>

This is my preferred way to go.



Inspiring
September 30, 2006

"disco-logic" <webforumsuser@macromedia.com> wrote in message
news:efk7gi$2f1$1@forums.macromedia.com...
> hmm afraid that the kind of code I was using. The problem is you cant
> take a
> variable out of one instance and use it in another.
>
> I know that soldier1._rotation is working cos it work for soldier clip.
>
> The problem comes when you want to pass soldier1._rotation onto the bullet
> cos
> a statement like
>
> bullet._rotation = soldier1._rotation;
>
> within the code for the bullet will simply decide that it cant find
> soldier1._rotation. What I think I need is a way to make the value public
>

okay, here is what you want to check (for this case and any case when you
have some issue like this --- unexpected behavior)

TRACE, TRACE, TRACE.

Each bullet is coming from an attachMovie or a duplicateMovieClip, right???

In either case, in your code you have:

onClipEvent(load) {
this._rotation = solder1._rotation;
}

which is a valid statment. This says, find the rotation value of soldier1
and assign it to this (the Bullet clip)

So, TRACE...
add
trace(soldier1._rotation);
to the onClipEvent(load) handler above. You see that soldier1._rotation is
undefined.

next add another TRACE...
add
trace(this);
to the handler.

You will see that 'this' is referring to your bullet. But, soldier1 is not
in the bullet instance, it is in the _parent instance (most likely - depends
on your setup) so, you should try

onClipEvent(load) {
this._rotation = _parent.soldier1._rotation;
}

if that doesn't work, add the following traces and post their output

trace(this);
trace(this._parent);






Ive made a new topic for this cos the last one went wildly off-topic...

Im trying to use info from the soldier instance to set up bullets he fires.
Each new bullet wants to be its own instance/mc whatever. Thing is that I
cant get the info out of _root.soldier and into _root.bulletX (where X is an
arbitary value)

there is code in the bullet onClipEvent(load) like
this._rotation = soldier1._rotation;
Which by the looks of some traces Ive done just gives soldier._rotation as
undefined.

How can I pass a value out of soldier to use here?