How to properly use Yield for a coroutine?

I have some functions that fire one after the other and I want to make sure the first one is finished before the second one starts.

I used "yield" before the function names, ie:

yield myFirstFunction();
yield mySecondFunction();

Sometimes this works fine, but other times it gives an error:

"It is not possible to evaluate an expression of type 'void'."

If I remove yield from the first line it still errors out.

What's weird is that sometimes this works fine. Even for the block of code. It just stops working when I change something down the line but I don't really know what it is that's breaking it.

Can anyone shed some light on this? I searched the forum but found nothing. The errors in question are happening in a Javascript script.

ADDED: Here is one of the functions that won't let me yield it:

function FillCharactersThumbArray() {
// loads in thumbnail images from a local folder and puts them into the appropriate character thumb in the listCharacters[] array...

    for (nng=0;nng<listCharacters.length;nng++)
    {
        var www1 = new WWW ("file:///c:/SS/AssetPacks/thumbs/c/tn_"+listCharacters[nng].gender+"_"+listCharacters[nng].image+".png");
        yield www1;

        listCharacters[nng].image = www1.texture;
    }   

}

the function that you call needs to be of type IEnumerator - this is done implicitly when you use yield in the function, but if you add in a return (or it is possible to get through the function without hitting a yield), it'll see it as a void function

if you want to tell the compiler to do it explicitly, you could do function myFirstFunction() : IEnumerator {

Edit - In the example you posted, the compiler can't be sure there will be a yield if the string is too short (0 chars) - so it's confused as to the return type

you could fix it by putting yield; at the end, or making the function IEnumerator

what Mike meant is following:

function myFirstFunction():IEnumerator {
 ...
}
function mySecondFunction():IEnumerator {
 ...
}

... 

yield myFirstFunction();
yield mySecondFunction();

this way the compiler wont get confused about the correct type.

you could do something like a call back, so even though you cant get the return right away, you can have function B call function D in the same class as function A to continue on where A left off.

   class Face{
       var brain:Brain;
       function Talk(){
          brain.Think(OfWhatToSay)
       }
       function OfWhatToSay(words:String){
         print(words)
       }
    }
    
    class Brain{
       function Think(callBack:function(String)){
          callBack(GetWordsToSayElseWhereInThisClass());
       }
       function GetWordsToSayElseWhereInThisClass():String{
          return "Giberish";
       }
    }

check out this for an intro for callbacks.