Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Dynamicly change AceSlide allowDrag Status — Gideros Forum

Dynamicly change AceSlide allowDrag Status

twisttaptwisttap Member
edited April 2013 in General questions
@ ar2rsawseen or someone who tried this before. I need to set drag status of AceSlide during runtime. Is that possible ?
I tried:

function AceSlide:setDrag(s)
if (self.conf.allowDrag == true) then
print("Drag Off")
self.conf.allowDrag = false
for i = 1, self.total do

local xtarget = self:getChildAt(i)
--self:getChildAt(i):setAlpha(0)
self:getChildAt(i):removeEventListener(Event.MOUSE_DOWN, self.onMouseDown, xtarget)
self:getChildAt(i):removeEventListener(Event.MOUSE_MOVE, self.onMouseMove, xtarget)
self:getChildAt(i):removeEventListener(Event.MOUSE_UP, self.onMouseUp, xtarget)
end
end

but no luck. Any ideas ?

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited April 2013
    @twisttap haven't tried, but yes it should be as simple as adding/removing listeners.

    Firstly I think it should be
    self:getChildAt(i):removeEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
    as in self instead of xtarget because that is how they've been added.
  • @ar2rsawseen Well it does not working this way any other ideas ? :)
  • I found this in AceSlide.lua

    --dirty little fix
    local fix = Sprite.new()
    -- self:addChild(fix)
    if self.conf.allowDrag then
    fix:addEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
    fix:addEventListener(Event.MOUSE_MOVE, self.onMouseMove, self)
    fix:addEventListener(Event.MOUSE_UP, self.onMouseUp, self)
    end

    commenting out add child(fix) seems to work now but I wonder what is this for ?

    Likes: anneMurielle

    +1 -1 (+1 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    Will you believe me if I say that I don't remember. :)

    AceSlide actually was my first component created for Gideros, thus I may have created some mistakes there that could be avoided now, but until it done the job, I never bothered to fix it :)

    Basically if removing this works, it means that inside :setDrag(s) event is not removed from all elements.

    Thus you may need to update it as:
    function AceSlide:setDrag(s)
        if (self.conf.allowDrag == true) then
             print("Drag Off")
             self.conf.allowDrag = false
             for i = 1, self:getNumChildren() do
     
                 local xtarget = self:getChildAt(i)
                 --self:getChildAt(i):setAlpha(0)
                 self:getChildAt(i):removeEventListener(Event.MOUSE_DOWN, self.onMouseDown, self)
                 self:getChildAt(i):removeEventListener(Event.MOUSE_MOVE, self.onMouseMove, self)
                 self:getChildAt(i):removeEventListener(Event.MOUSE_UP, self.onMouseUp, self)
             end
        end
    to remove events from all children :)

    And don't worry, I won't go offline till we resolve this ;)
  • ı just commendted out the whole fix stuff and it works now. :) Thanks
  • bowerandybowerandy Guru
    edited April 2013
    @twisttap, I don't want to jump in here inappropriately (and apologies to @ar2rsawseen) but I have a slider component (BhItemSlider) that does what you want. There is a function beSlideEnabled(tf) that takes a boolean value and can turn sliding on and off. It also has a plethora of other features like momentum sliding etc.

    The following demo only shows text scrolling but of course any objects can be added to the slider:


    You can get the code and the demo project from my GitHub repo here.

    best regards

    Likes: Ozkar619, OZApps

    +1 -1 (+2 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    oh @bowerandy I really don't mind, not at all. Whatever helps the members is good for me :)
Sign In or Register to comment.