×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    3

    Softkeys problem in Flash Lite 2

    Here's my issue:
    In one frame (a welcome screen for my app) i assigned left and right softkeys via
    it goes perfectly to the second frame, in which i had the keys reasigned.

    The output of right softkey is perfect ("help"), but the left softkey outputs both "left pressed" and "send". Now this is only trace, but i'm planning to assign different softkeys to different frames, and that may cause problems.

    I added some more functionality, and it gets even worse. So the main question is, how can i reset the softkeys, so in every other frame they would do completely (and ONLY) other things?!?

    This kinda makes me stuck, and since deadlines are coming (school project) i would really appreciate some swift help. Thanks

    the Code

    Code:
    //frame 1
    fscommand2("SetSoftKeys", "left", "right");
    var myListener = new Object();
    	myListener.onKeyDown = function() {
    		if (Key.getCode() == ExtendedKey.SOFT1) {
    			// Handle left soft keypress event.
                            trace ("left pressed");
    			
    	
    		} else if (Key.getCode() == ExtendedKey.SOFT2) {
    			// Handle right soft keypress event.
    			gotoAndStop(2);
    		}
    	};
    Key.addListener(myListener);
    
    //frame 2
    fscommand2("resetSoftKeys");
    fscommand2("setSoftKeys" , "left" , "right");
    var myListener1 = new Object();
    	myListener1.onKeyDown = function() {
    		if (Key.getCode() == ExtendedKey.SOFT1) {
    			// Handle left soft keypress event.
    			trace ( "send");
    	
    		} else if (Key.getCode() == ExtendedKey.SOFT2) {
    			// Handle right soft keypress event.
    			trace ("help");
    		}
    	};
    Key.addListener(myListener1);

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2006
    Location
    Mumbai, India
    Posts
    48

    Re: Softkeys problem in Flash Lite 2

    Resetting the soft keys via FSCommand("ResetSoftKeys"); in frame 2 is not the correct method because this will only release your control on the soft keys within the application.

    In your code, you might notice that when you move from frame1 to frame2, your KeyListener Object (i.e myListener) is still active. So even when you have a new KeyListener Object(i.e myListener1) defined in frame2, the keys on your phone will continue to listen to both the active KeyListener Objects.

    The correct method is to remove the KeyListener when moving to a new frame, and then redefining the KeyDown function again with the same listener object.

    Code:
    //frame 1
    fscommand2("SetSoftKeys", "left", "right");
    var myListener = new Object();
    	myListener.onKeyDown = function() {
    		if (Key.getCode() == ExtendedKey.SOFT1) {
    			// Handle left soft keypress event.
                            trace ("left pressed");
    			
    	
    		} else if (Key.getCode() == ExtendedKey.SOFT2) {
    			// Handle right soft keypress event.
    			 Key.removeListener(_root.myListener);
                             // -------or Key.removeListener(this);
                             gotoAndStop(2);
    		}
    	};
    Key.addListener(myListener);
    
    //frame 2
    	myListener.onKeyDown = function() {
    		if (Key.getCode() == ExtendedKey.SOFT1) {
    			// Handle left soft keypress event.
    			trace ( "send");
    	
    		} else if (Key.getCode() == ExtendedKey.SOFT2) {
    			// Handle right soft keypress event.
    			trace ("help");
    		}
    	};
    Key.addListener(myListener);

  3. #3
    Registered User
    Join Date
    Dec 2008
    Location
    Cochin, Kerala, India
    Posts
    84

    Re: Softkeys problem in Flash Lite 2

    Can you please send a sample program (complete) for Keylistener of mobile Phones....... Please do reply..............
    Last edited by vinuk4u; 2010-02-04 at 11:52.

  4. #4
    Regular Contributor
    Join Date
    Jan 2007
    Posts
    135

    Re: Softkeys problem in Flash Lite 2

    I don't think that there is a "per frame" function that is called when you exit a frame so it is not easy (but of course possible )to clean up and remove listeners.

    Another way is to have one listener defined in the main frame which dispatches the event to the proper "per frame" key decoding depending which frame is active.

    keyListener = new Object();
    Key.addListener(keyListener);
    keyListener.onKeyUp =function() {
    // launch the key function for each frame
    eval(currentFrame+"KeyProcessing") ();
    }

    here "currentframe is a global variable that is updated when a frame is started: example currentframe="login".

    then you have to define a function in the action script of the "login" frame which is:


    loginKeyProcessing = function () {

    switch(Key.getCode()) {
    case Key.ENTER:
    break;
    // C key
    case 8:

    break;
    case ExtendedKey.SOFT1:
    trace("left softkey");

    break;
    case ExtendedKey.SOFT2:
    trace("right button");

    break;

    }


    }

    Of course both are working fine.
    Select teh one you want
    Have a nice day
    Jean-philippe
    jean-philippe

  5. #5
    Nokia Developer Champion
    Join Date
    Jul 2008
    Location
    Pakistan
    Posts
    1,065

    Smile Re: Softkeys problem in Flash Lite 2

    Quote Originally Posted by Kloucek View Post
    Here's my issue:
    In one frame (a welcome screen for my app) i assigned left and right softkeys via
    it goes perfectly to the second frame, in which i had the keys reasigned.

    The output of right softkey is perfect ("help"), but the left softkey outputs both "left pressed" and "send". Now this is only trace, but i'm planning to assign different softkeys to different frames, and that may cause problems.

    I added some more functionality, and it gets even worse. So the main question is, how can i reset the softkeys, so in every other frame they would do completely (and ONLY) other things?!?

    This kinda makes me stuck, and since deadlines are coming (school project) i would really appreciate some swift help. Thanks

    the Code

    Code:
    //frame 1
    fscommand2("SetSoftKeys", "left", "right");
    var myListener = new Object();
    	myListener.onKeyDown = function() {
    		if (Key.getCode() == ExtendedKey.SOFT1) {
    			// Handle left soft keypress event.
                            trace ("left pressed");
    			
    	
    		} else if (Key.getCode() == ExtendedKey.SOFT2) {
    			// Handle right soft keypress event.
    			gotoAndStop(2);
    		}
    	};
    Key.addListener(myListener);
    
    //frame 2
    fscommand2("resetSoftKeys");
    fscommand2("setSoftKeys" , "left" , "right");
    var myListener1 = new Object();
    	myListener1.onKeyDown = function() {
    		if (Key.getCode() == ExtendedKey.SOFT1) {
    			// Handle left soft keypress event.
    			trace ( "send");
    	
    		} else if (Key.getCode() == ExtendedKey.SOFT2) {
    			// Handle right soft keypress event.
    			trace ("help");
    		}
    	};
    Key.addListener(myListener1);
    The thing you r forgetting is removing the key listener.. If you are going to add new listner than remove the previous listener first.Just add this before declaring new listner :
    Code:
    Key.removeListener(myListener);
    Moreover , u can find one key listener tutorials here:
    Key Listeners

    Hope it helps u ..Enjoy Flash Programming..
    Best Regards,
    SajiSoft

Similar Threads

  1. Flash Lite - Classes or timeline?
    By jt_01 in forum [Archived] Flash Lite on Nokia Devices
    Replies: 18
    Last Post: 2008-07-05, 21:10
  2. Flash lite 1.x and Databases
    By abolfoooud in forum [Archived] Flash Lite on Nokia Devices
    Replies: 7
    Last Post: 2008-04-15, 13:56
  3. Virtual World API with Flash Lite
    By joaach in forum [Archived] Flash Lite on Nokia Devices
    Replies: 0
    Last Post: 2008-03-09, 18:35
  4. Starting Flash Lite swf with an SMS
    By indy_materna in forum [Archived] Flash Lite on Nokia Devices
    Replies: 1
    Last Post: 2008-01-03, 20:18
  5. flash lite 2.0 upgrade possible?
    By BO_frank in forum General Development Questions
    Replies: 7
    Last Post: 2006-08-17, 14:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×