Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. btnCount.addEventListener(MouseEvent.CLICK, countVowels);
  2. txtinSentence.addEventListener(MouseEvent.CLICK, clearLabels);
  3. function countVowels(e:MouseEvent):void {
  4.     var phrase: String;
  5.     var current_char: String;
  6.     var is_vowel: Boolean;
  7.     var num_vowels: int;
  8.     var vowel_types: String;
  9.    
  10.     vowel_letters = "aeoui";
  11.     phrase = txtinSentence.text;
  12.    
  13.    
  14.     // iterate through each char, looking for vowels
  15.     for (i = 0; i < str.length; i++) {  // 'i' is a counter
  16.         current_char = phrase.charAt(i);    // use 'i' to index the phrase
  17.         if(vowel_letters.indexOf(current_char) >= 0) {   // actionscript is horrible
  18.             num_vowels += 1;    // yay there's a vowel
  19.         }
  20.     }
  21.    
  22.     // output the text
  23.     lblOutput.text += "There are " + num_vowels + " in the sentence";
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement