AS3 - Parsing ... (rest) arguments

Here in my code I have two functions that each require one argument but will accept additional arguments through the use of …(rest). The difficulty I am having is getting the first function to parse its arguments in such a way that if/when it finds bRequired, bRequired is passed to the second function as its required argument, and all of the arguments following bRequired are passed to it using …(rest). The way I’ve set things up now is just makeshift with all of the second function’s …(rest) arguments received as an array. I’m not sure if this is the right idea. I’m stumped by how to separate the array elements so that they can be parsed in the same dynamic fashion as the first function – if, for example, there were a third function to which more arguments needed to be sent. Can the parsing and passing still be performed dynamically without the array? How would someone who is not a noob do this? :slight_smile:


package {
    import flash.display.Sprite;

    public class Test extends Sprite{
        
            private var aRequired:String = "This is a required argument in func1"
            private var bRequired:String = "This is a required argument in func2"
        
        public function Test(){
            
            func1(aRequired, "One potato", "Two potato", bRequired, "Three potato", "Four potato")
        }
        
        public function func1(required:String, ...rest):void{
            trace("func1 required argument: " + required);
            trace("func1 ... (rest) number of arguments: " + rest.length)
            trace("func1...(rest) arguments are: ");
            for(var i:uint = 0; i<rest.length;i++){
                trace("   "+ rest*);
            }
            for(i = 0;i<rest.length;i++){
                if(rest* == bRequired){
                    var nextRequired:String = rest*
                    var func2Arr:Array = new Array()
                    func2Arr.push(nextRequired);
                    for(i = i; i < rest.length; i++){
                        func2Arr.push(rest*);
                    }    
                    func2(nextRequired, func2Arr)
                    return;
                }
            }
        }
            
        public function func2(required:String, ...rest):void{
            trace("func2 required argument: " + required);
            trace("Func2 ... (rest) number of arguments: " + rest.length);
            for(var i:uint = 0; i<rest.length;i++){
                trace("   " + rest*);
            }
        }
    }
}

Fingers