Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Assigning attributes to an object

New Here ,
Jun 09, 2015 Jun 09, 2015

Hi, I'm trying to make a game so testing out a lot of interactions between different objects and time frames.

Currently, I have a red box and a green box. I wrote some keyboard listeners and the green box can move left and right

with the left/right arrow keys (the code is inside the object (green).(pic1)

811518b065.png

I have a red box that moves up and down with a tween(pic2) and once it reaches the end of the tween, it loops back

to the beginning. If (notice == true) on frame 21 however, it will go to the next frame, where it will become blue and stop on that frame.

4cae969ec4.png

With my trace, I know the hitTest works and produces true when the green and red box overlap, however:

Goal: My goal is to make it so when the green box touches(with hitTestObject) the red box, the variable notice becomes true

and when the red box reaches frame 21, (notice == true) becomes true and goes to frame 22.

Question: I guess the ultimate question is how I can assign an attribute/variable to an object, and be able to retrieve the

value of that attribute/variable from both inside or outside the object.

Thanks

TOPICS
ActionScript
456
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jun 09, 2015 Jun 09, 2015

If I'm reading this correctly, then the solution is simple: any property of an object, custom or not, can be referenced through the object. So, if the object "red" is on the main timeline and you want a property of "red", then you can get to that property from the main timeline as you show: red.objectName. If you want to get to the property from within another timeline, you need to path your way to the object. So, if I'm reading this correctly, the object green contains code that you want to use

...
Translate
LEGEND ,
Jun 09, 2015 Jun 09, 2015

If I'm reading this correctly, then the solution is simple: any property of an object, custom or not, can be referenced through the object. So, if the object "red" is on the main timeline and you want a property of "red", then you can get to that property from the main timeline as you show: red.objectName. If you want to get to the property from within another timeline, you need to path your way to the object. So, if I'm reading this correctly, the object green contains code that you want to use to refer to the property in red. So, to get to red from green you will need to move "up" one level in the timeline structure. So it should be something like: MovieClip(parent).red.objectName.

Does that help, or make it worse?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 09, 2015 Jun 09, 2015
LATEST

Yes, that's exactly what I was looking for. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines