Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Movieclip class — Gideros Forum

Movieclip class

NinjadoodleNinjadoodle Member
edited October 2015 in General questions
Hi guys

I have a movie clip class, which I would like to create in my scene and change it's frame on click.
LightSwitch = Core.class(Sprite)
 
function LightSwitch:init(x, y, container)
	local frames = {}
 
	frames[1] = Bitmap.new(Texture.new("media/lightSwitch.png", true))
	frames[2] = Bitmap.new(Texture.new("media/lightSwitchOn.png", true))
 
	frames[1]:setAnchorPoint(0.5, 0.5)
	frames[2]:setAnchorPoint(0.5, 0.5)
 
	local mc = MovieClip.new{
		{1, 1, frames[1]}, 
		{2, 2, frames[2]}, 
	}
	mc.frame = 1
 
	mc:setPosition(x, y)
	self:addChild(mc)
	container:addChild(self)
end
I create it inside my scene like this ...
function Scene1:onTransitionInEnd()
	self.lightSwitch = LightSwitch.new(160, 160, layerMG)
	self.lightswitch:gotoAndStop(1)
end
.... but I get an error when trying to make it goto frame 1

If anyone can help, that would be awesome!

Thank you in advance!

Comments

  • if you need to operate the movieclass inside your lightswitch later then you have to make it not local, e.g.
    self.mc = MovieClip.new...
    instead of local mc=...
    and then you can do:
    self.lightswitch.mc:gotoAndStop(1)

    also you can add additional functions to your class which handle this by themselves so you don't deal with the mc directly.
    e.g.
    function LightSwitch:gotoAndStop(i)
    self.mc:gotoAndStop(i)
    end
     
    self.lightSwitch:gotoAndStop(1)
    will work. btw be careful about uppercase, you wrote self.lightswitch once and self.lightSwitch the other time, so that would crash even if you do as i said above.
  • keszeghkeszegh Member
    Accepted Answer
    note that a local value is reachable only inside that function and not inside any function of the same class. that's why self.. is needed.

    Likes: Ninjadoodle

    +1 -1 (+1 / -0 )Share on Facebook
  • Thanks heaps, that makes it a lot clearer :)
Sign In or Register to comment.