Making a window fade in and out?

Discussion in 'Mac Programming' started by Blakeasd, Aug 21, 2010.

  1. Blakeasd macrumors 6502a

    Joined:
    Dec 29, 2009
    #1
    I am following a book and it gives me this code:

    Code:
    -(IBAction)displayOrCloseWindow:(id)sender {
    	//Fades in & out nicely
    	if(isOpen) {
    		[[self animator] setAlphaValue:0.0];
    		isOpen = NO;
    	}
    	else {
    		[[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
    		[self makeKeyAndOrderFront:self];
    		[[self animator] setAlphaValue:1.0];
    		isOpen = YES;
    	}
    }

    It gives me an error when compiling it? Can anyone help?
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
  3. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    Yes, the compiler. Read the error message. What does it say?
     
  4. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #4
    The error is: 'isOpen' undeclared (first use in this function)
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    What is the book? Be specific.


    Post the code that defines the @interface for the class containing displayOrCloseWindow:.

    If there isn't an isOpen instance variable, and there isn't one in a superclass, then you have the reason for the error: there is no variable named isOpen.

    If the @interface does define an isOpen instance variable, make sure it's spelled exactly the same, including case.
     
  6. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    That explains it. The compiler tells you exactly what is wrong: You haven't declared "isOpen". Where did you think you declared it? Did you spell it wrong?
     
  7. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #7
    The interface didn't declare anything. Does anyone know how to make a window fade in and out with out this book? Thanks
     
  8. GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
  9. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #9
    Well, you know how to fix it then. The sample code gives you the essential steps (most importantly use [self animator]), and you are supposed to fill out the rest. Could it be that your question is not really how to make a window fade in and out, but how to write a Cocoa application?
     
  10. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #10
    Which book? You haven't told us a title or author yet.


    When I google the code snippet, I only find this:
    http://dbachrach.com/blog/2008/01/cocoa-code-snippet-simple-window-fade-inout/

    That's not a book, as far as I can tell. The article even says you have to define an isOpen instance variable.
     
  11. Blakeasd thread starter macrumors 6502a

    Joined:
    Dec 29, 2009
    #11
    Whoops

    Sorry about that I didn't see the part at the bottom telling my to add an instance variable. Sometimes I get so excited when I see the code I forget to read on:) It works now, thanks!
     
  12. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #12
    I'm glad it works, but I'm still puzzled why you said the code was from "following a book".

    What book?
     

Share This Page