scrollview problem with insert shapes ?

hello bro

i am trying to insert rects table that contain 10 objects (all those objects have touch listener) to scrollview, but i get error insert to scrollview 

this is some part of my code:


local widget=require “widget”

local scorllView =widget.newScrollView()

local rect1s = {}

for i = 1, 10 do

   rect1 =display.newRect(display.contentCenterX,0,250,200)  

rect1s[i] = rect1

end

for i=1 ,10 do

scrollView:insert (rect1s[i])

  end 

function touchListener( event )

–here some simple code 

       end

   

   

for i=1 , 10 do

rect1s[i]:addEventListener(“touch”,touchListener)

end 

  1. Please format your code when posting.
    formatyourcode.jpg
     

  2. I see a number of spelling errors so I assume you retyped this instead of pasting it from your code directly (the latter is a better practice).

    local widget = require “widget” local scrollView = widget.newScrollView() local rects = {} for i = 1, 10 do local tmp = display.newRect(display.contentCenterX,0,250,200) rects[#rects+1] = tmp end for i = 1, #rects do local tmp = rects[i] scrollView:insert( tmp ) end local function touchListener( self, event ) --here some simple code end   for i = 1, #rects do local tmp = rects[i] tmp.touch = touchListener tmp:addEventListener( “touch” ) end

I had posted direclty . I will use formatting for posting in future. thanks for your notice.

I see you add some code to my code, could you please explain what is my issue?!

thanks for your help mr @roaminggamer

Original Issues

If you pasted that code directly into the forums from your code via copy-paste, then the error(s) were likely related to these issues

  • spelling/typos:
    • local scorllView =widget.newScrollView()
    • scrollView :insert  << This should have produced a very clear error message in the console.
  • use of globals when locals are much appropriate:
    •   rect1 =disp …     should be   local rect1 =disp …
    • function touchListener( event )   should be   local function touchListener( event )

What did I add/change?

I changed the way your touch listener is written.  I made into a local listener which is much better, cleaner, and safer.

local function touchListener( self, event ) --here some simple code end for i = 1, #rects do local tmp = rects[i] tmp.touch = touchListener tmp:addEventListener( "touch" ) end

this error message what i got 

Right.

You spelled it  scorllView  when you defined it.

You spelled it scrollView when you used it.

this is really my problem  :lol:

thank you too much bro @roaminggamer

Hey, I don’t mind helping, but be sure to do enough debugging in the future.

This was clearly laid out by the error message.  I realize, sometimes we get code blind when looking at our own code so I get it.  You may have simply missed the typo.  We all do this sometimes.

Tip: In cases like this, do the following:

  1. Select the word/variable that is being complained about on the line where the error message says the problem is.

  2. Go to the top of the file.

  3. Use the editor search feature to look for all instances of that word and see if they match what you expect.  

I am on learning mode ,ok

  1. Please format your code when posting.
    formatyourcode.jpg
     

  2. I see a number of spelling errors so I assume you retyped this instead of pasting it from your code directly (the latter is a better practice).

    local widget = require “widget” local scrollView = widget.newScrollView() local rects = {} for i = 1, 10 do local tmp = display.newRect(display.contentCenterX,0,250,200) rects[#rects+1] = tmp end for i = 1, #rects do local tmp = rects[i] scrollView:insert( tmp ) end local function touchListener( self, event ) --here some simple code end   for i = 1, #rects do local tmp = rects[i] tmp.touch = touchListener tmp:addEventListener( “touch” ) end

I had posted direclty . I will use formatting for posting in future. thanks for your notice.

I see you add some code to my code, could you please explain what is my issue?!

thanks for your help mr @roaminggamer

Original Issues

If you pasted that code directly into the forums from your code via copy-paste, then the error(s) were likely related to these issues

  • spelling/typos:
    • local scorllView =widget.newScrollView()
    • scrollView :insert  << This should have produced a very clear error message in the console.
  • use of globals when locals are much appropriate:
    •   rect1 =disp …     should be   local rect1 =disp …
    • function touchListener( event )   should be   local function touchListener( event )

What did I add/change?

I changed the way your touch listener is written.  I made into a local listener which is much better, cleaner, and safer.

local function touchListener( self, event ) --here some simple code end for i = 1, #rects do local tmp = rects[i] tmp.touch = touchListener tmp:addEventListener( "touch" ) end

this error message what i got 

Right.

You spelled it  scorllView  when you defined it.

You spelled it scrollView when you used it.

this is really my problem  :lol:

thank you too much bro @roaminggamer

Hey, I don’t mind helping, but be sure to do enough debugging in the future.

This was clearly laid out by the error message.  I realize, sometimes we get code blind when looking at our own code so I get it.  You may have simply missed the typo.  We all do this sometimes.

Tip: In cases like this, do the following:

  1. Select the word/variable that is being complained about on the line where the error message says the problem is.

  2. Go to the top of the file.

  3. Use the editor search feature to look for all instances of that word and see if they match what you expect.  

I am on learning mode ,ok