Code.GeekInterview.com
 
Code Samples Flash
 

Implement Custom Sort


Code ResourceAuthor: lavanyarani  

Difficulty Level: Intermediate

Published: 10th Nov 2009   Read: 1121 times  

Filed in: Flash
Add Comment


 

 

Sponsored Links


 

 
The following actionscript code shows how to implement custom sort
 


Sample Code
  1. Step-1: Create 4 input texts(boxes) and give them names n1, n2, n3, n4  
  2.              respectively in the properties panel.
  3.  
  4. Step-2: Create 3 buttons with the test on them as “sort”.
  5. Step-3: Create another 4 input texts (boxes) and give each of them names    
  6.              like r1, r2, r3, r4 respectively.
  7. Step-4: Select the “sortbutton and write the following code in the script      
  8.              pane
  9.  
  10.  
  11. on (release) {
  12. a=[t1.text,t2.text,t3.text,t4.text];
  13. var i:Number;
  14. var j:Number;
  15. i=0;
  16. j=0;
  17. var temp:String;
  18. for(i=0;i<a.length;i++)
  19. {
  20.                 for(j=i+1;j<a.length;j++)
  21.                 {
  22.                         if(a[i]>a[j])
  23.                         {
  24.                                 temp=a[i];
  25.                                 a[i]=a[j];
  26.                                 a[j]=temp;
  27.                         }
  28.                 }
  29. }
  30. r1.text=a[0];
  31. r2.text=a[1];
  32. r3.text=a[2];
  33. r4.text=a[3];
  34. }
  35.  
  36.  
  37. Step-5: Press ctrl+enter to test the movie and enter any 4 strings in the text boxes and press the buttonsort” the texts entered will be sorted and will be printed in the other text boxes.
  38.  
  39.  
  40.  
Copyright GeekInterview.com


Next Article: Sorting and Reversing an Array


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. lavanyarani32140

Active Coders

# Coder NameCodes
1. lavanyarani13

Refined Tags