Want to use Widget events with a for loop

Never Mind figured it out by myself :slight_smile:  !!!

I have 80 widget buttons that will do the same thing based on their number.  I am trying to reduce the amount of code I am writing so a tried a loop like so.  So when onEvent1 or onEvent2  I am getting error iWARNING: Failed to find image(NumbersB/"…i…".png)

The file I use is ‘NumbersB/1’, ‘NumbersB/2’,’ NumbersB/3’,etc

 [lua]

local theOwner = _G

for i = 1,4 do

  theOwner[“onEvent”…i]= function (event)

    if event.phase == “ended” then

        if theOwner[“flag”…i] == false then

           theOwner[“B”…i] = display.newImageRect(‘NumbersB/"…i…".png’,50,50)

           theOwner[“B”…i].x=  theOwner[“myButton”…i].x

           theOwner[“B”…i].y=  theOwner[“myButton”…i].y

           screenGroup:insert(theOwner[“B”…i])

           print (‘theOwner[“flag”…i] on’)

           theOwneWidget[“flag”…i] =true

      elseif theOwner[“flag”…i] == true then 

            display.remove(theOwner[“B”…i])

                theOwner[“B”…i] = nil

                theOwner[“flag”…i] = false

               print (‘theOwner[“flag”…i] off’)

          end

      

     end

    end            

end

    myButton1 = widget.newButton{

        defaultFile = “NumbersA/1.png”,

        left = w/2,

        top = h/2,

          width =w1, height = h1,

         onEvent = onEvent1

    }

    screenGroup:insert(myButton1)

     myButton2 = widget.newButton{

        defaultFile = “NumbersA/2.png”,

        left = w/2+70,

        top = h/2,

          width =w1, height = h1,

         onEvent = onEvent2

    }

    screenGroup:insert(myButton2)

     myButton3 = widget.newButton{

        defaultFile = “NumbersA/3.png”,

        left = w/2+140,

        top = h/2,

          width =w1, height = h1,

         onEvent = onEvent3

    }

    screenGroup:insert(myButton3)

     myButton4 = widget.newButton{

        defaultFile = “NumbersA/4.png”,

        left = w/2+210,

        top = h/2,

          width =w1, height = h1,

         onEvent = onEvent4

    }

    screenGroup:insert(myButton4)

[/lua]