943,893 Members | Top Members by Rank

Ad:
Jul 11th, 2008
0

symbols & arrays

Expand Post »
Hello
I have a quick question. I will have to learn syntax for action script. Before I research my objective. Can someone enlighten me with a yes or no (example code would be awesome).
Question: Can I create a Array of symbols and then manipulate them by making them apear and disapear from a lower layer. (Bring forward & move back)?
Or is there another way?
Thanks
Steve
Reputation Points: 7
Solved Threads: 2
Posting Pro
ceyesuma is offline Offline
524 posts
since Aug 2007
Jul 11th, 2008
0

Re: symbols & arrays

It's definitely possible to switch the stacking order of symbols. The manner in which you do it differs in ActionScript 2 and ActionScript 3, though.

IN AS2:
You will use the method "swapDepths" and "getNextHighestDepth()" in order to move a symbol to the top.

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. // First, create an array:
  2. var myArray:Array = new Array(mySymbol1, mySymbol2, mySymbol3);
  3.  
  4. // This code will move mySymbol1 to the very front
  5. mySymbol1.swapDepths(this.getNextHighestDepth());
  6.  
  7. // This code will move the second item in the array to the very front
  8. myArray[1].swapDepths(this.getNextHighestDepth());
  9.  
  10. // This code will move the third item in the array to the very front when the user clicks on mySymbol1
  11. mySymbol1.onRelease = function() {
  12. myArray[2].swapDepths(this._parent.getNextHighestDepth());
  13. }

In AS2, it's important to keep an eye on the target. You'll notice in the first two examples, I use "this" to indicate the movie clip that flash should determine the "getNextHighestDepth" value for, but in the last one I use "this._parent". That's because in a mouse function like onRelease, "this" refers to the movie clip that called the function.

IN AS3:
It's similar to AS2, except now you're using setChildIndex instead of swapDepths and numChildren instead of getNextHighestDepth().

Graphics and Multimedia Syntax (Toggle Plain Text)
  1. // First, create an array:
  2. var myArray:Array = new Array(mySymbol1, mySymbol2, mySymbol3);
  3.  
  4. // This code will move mySymbol1 to the very front
  5. this.setChildIndex(mySymbol1, this.numChildren - 1);
  6.  
  7. // This code will move the second item in the array to the very front
  8. this.setChildIndex(myArray[1], this.numChildren - 1);
  9.  
  10. // This code will move the third item in the array to the very front when the user clicks on mySymbol1
  11. mySymbol1.addEventListener(MouseEvent.CLICK,swapDepths);
  12.  
  13. function swapDepths(e:Event):void {
  14. this.setChildIndex(myArray[2], e.target.parent.numChildren - 1);
  15. }

Again, note that you need to be careful in your targeting. For example, in the button click you need to use "e.target.parent" in order to indicate the parent of the clicking movie clip.

Have fun!

--eric
Reputation Points: 10
Solved Threads: 4
Newbie Poster
erico564 is offline Offline
22 posts
since Apr 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Graphics and Multimedia Forum Timeline: uploading image folder
Next Thread in Graphics and Multimedia Forum Timeline: Programming against design, who is the best?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC