Welcome, Guest. Please login or register.
Did you miss your activation email?
02/07/12, 08:12
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash and AS 3 (Moderators: papachan, kofi addaquay)
| | |-+  Array Index + Reading in Reverse Order
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: Array Index + Reading in Reverse Order  (Read 792 times)
worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« on: 07/16/10, 09:42 »

Hi there-  I have a simple array that populates a textfield.  I want to read the array indices in reverse order when each is clicked from last to first.  For instance (and this is working):
Code:
//create array
var h:Array = new Array("a", "b", "c");
//create textfield code... truncated
//populate textfield
t.htmlText += "<a href='event:"+ h[h.length-1] +"'>"+ h[h.length-1] +"</a>"
//listen for TextEvent
tf.addEventListener(TextEvent.LINK, tfClicked);
function tfClicked(e:TextEvent):void {
  trace(getIndex());
  function getIndex():Number {
  [b]//if clicked from last to first it will trace (2,1,0)
  //but want it to trace (0,1,2)[/b]
  for (var i:uint = 0; i > h.length; i++) {
    if (h[i] == evt.text) {
      return i;
    }
  }
  return -1;
}


Any advice is appreciated!
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14593


View Profile
« Reply #1 on: 07/16/10, 13:23 »

Don't understand exactly the question ... how to trace array content in reverse order?

Jorge
Logged

Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #2 on: 07/16/10, 14:36 »

How about this:
Code:
for (var i:uint = h.length-1; i >= 0; i--) {
    if (h[i] == evt.text) {
      return i;
    }
Logged

happy flashing
Cool
Ronald
worked
Seasoned Programmer
***
Posts: 129


View Profile Email
« Reply #3 on: 07/19/10, 17:05 »

All good, just needed to calculate the array's (length - 1) - current index, for instance:

Code:
//create array
var h:Array = new Array("a", "b", "c");
//create textfield code... truncated
//populate textfield
t.htmlText += "<a href='event:"+ h[h.length-1] +"'>"+ h[h.length-1] +"</a>"
//listen for TextEvent
tf.addEventListener(TextEvent.LINK, tfClicked);
function tfClicked(e:TextEvent):void {
  trace(getIndex());
  function getIndex():Number {
  for (var i:uint = 0; i > h.length; i++) {
    if (h[i] == evt.text) {
      var cI:Number = (history.length - 1) - i;
      return cI;
    }
  }
  return -1;
}
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!