iphone - Cocos2d MenuItem Selector and Accessing Instance Variable -
i have instance variable declared in implementation file can accessed using property defined synthesize
@synthesize myproperty
now, want assign property inside selector event of menuitem in cocos2d library. can think of accessing myproperty in callback function. reason whenever access property says "property out of scope". tried assigned access self.myproperty worked!!
but have memory leak in self.myproperty. if release self.myproperty in dealloc throws exception saying have myproperty release.
update 1: (code)
nsstring *voice;
@property (nonatomic,retain) nsstring *voice; @synthesize voice;
-(void)repeatalphabet:(id)sender { *// cannot access voice variable in function.* [[simpleaudioengine sharedengine] playeffect:[[voice lowercasestring] stringbyappendingstring:@".caf"]]; } -(void) addrepeatbuttononscreen { ccmenuitemimage * menuitem1 =[ccmenuitemimage itemfromnormalimage:@"image1.png" selectedimage: @"image2.png" target:self selector:@selector(repeatalphabet:)]; ccmenu *menu = [ccmenu menuwithitems:menuitem1,nil]; menu.position = ccp(30, 450); [self addchild:menu]; }
assuming have defined ivar corresponding property called myproperty, , property either retain
or copy
: in dealloc should [myproperty release];
not [self.myproperty release]
.
update: after discussion , more code shown... 'out of scope' can symptom of not having retained value should retained. instance string value = @"value"
doesn't retain (and become out of scope), fixed using self.value = @"value"
or value = [@"value" retain]
.
Comments
Post a Comment