Question

I am trying to run a function from an IF statement, this is the function, It runs from a mouse click at the moment.

        //Show the bus route
    public function showRoute(Event:MouseEvent){

        bg.addChildAt(route1, 2);
        bg.addChildAt(dest1, 3);
        bg.removeChild(stop1);
        searchbar1.mouseEnabled = false;
        bg.addChild(busInfo);
        bg.removeChild(instructions);
        bg.addChild(searchResult1);
        busInfo.mouseEnabled = true;
        route1.mouseEnabled = false;
        dest1.mouseEnabled = false;
    }

This is the next function and IF statement that I want to run the showRoute function

        public function addMarker(e:TuioEvent):void {

        var fid_id = (e.tuioContainer as TuioObject).classID;

        if (fid_id == 0){
            showRoute(event:Event);
        }

    }
Was it helpful?

Solution

Change the function to allow it to accept a call without an event being passed:

public function showRoute(Event:MouseEvent = null){
    // code goes here
}

This way you can still have it run as a response to a mouse click but you can also call it without passing any event as a parameter:

showRoute();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top