Code Snippets for Developers in Themes forum
MyGreatPhone.com


Mobile Phone News Mobile Phone Shop Mobile Phone Forum Mobile Phone Downloads Mobile Phone Wallpapers

  Forums.MyGreatPhone.com > Mobile Phone Manufacturers > LG Forum > LG KU990 > Themes / Wallpapers / Hacking - Customisation > Themes



Code Snippets for Developers Thread

Themes Forum in Themes / Wallpapers / Hacking - Customisation Section


Code Snippets for Developers This page is intended to help theme developers add advanced features to their themes, and to ...

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1  
Old 21-01-2009, 03:45 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Code Snippets for Developers

Code Snippets for Developers

This page is intended to help theme developers add advanced features to their themes, and to help others start creating themes.

If there's something you'd like to know, or you want to submit a snippet to others, please contact me by PM.

INDEX:
__________________
Themes, Apps, Software: http://www.joeearl.co.uk
Touch Diamond | vTocco | Walkman | Weather Widget | Cube3D
enhanced shortCut | Create Themes for KU990 Guide | More

Last edited by joe13; 29-03-2009 at 04:41 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
The Following 2 Users Say Thank You to joe13 For This Useful Post:
long (24-08-2009), zodrakn (30-11-2009)
  #2  
Old 21-01-2009, 03:53 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Get Message Counts

Code:
function getMessages() {
    _root.GetMessageCount(); //Call to Nyx - updates message counts
    var inboxCount:Number = _root.inboxCount;
    var newInboxCount:Number = _root.newInboxCount;
    var draftCount:Number = _root.draftCount;
    var sentCount:Number = _root.sentCount;
    var outboxCount:Number = _root.outboxCount;
    //Check to see if message counts have loaded yet
    //it can take a few seconds at phone startup
    if (isNaN(inboxCount)) {
        inboxCount =  0;
        newInboxCount = 0;
        draftCount = 0;
        sentCount = 0;
        outboxCount = 0;
    }
    
    //Now do what you like with the inboxCount, newInboxCount
    //draftCount, sentCount and outboxCount variables
    //You probably want to update you messages counts every 
    //5 seconds or so.
}
Example Usage:
Simply call
Code:
getMessages();
everytime you want to update your message counters.
At the end of the function you would normally add a few statements to put the message counts into text-boxes, such as
Code:
    //put this at the end of the getMessages function
    my_text.text = newInboxCount + "/" + inboxCount
would update the 'my_text' text-box with the number of new messages and total messages in the users inbox.

You cannot get message counts for e-mails.
Also it is not possible to retrieve the number of missed calls etc.

Last edited by joe13; 08-02-2009 at 11:29 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
  #3  
Old 21-01-2009, 03:54 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Haptic Feedback

Code:
platform.touch_sound();
This simple snippet makes the screen vibrate when called - generally used with the onPress action of buttons.

Example Usage:
Code:
my_btn.onPress = function() {
    platform.touch_sound();
}
Makes the button with the instance name 'my_btn' vibrate when pressed on the phone.

Last edited by joe13; 08-02-2009 at 11:29 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
  #4  
Old 25-01-2009, 12:32 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Reverse Playback

Want to play an animation, but in reverse? Add this code to your theme:

Code:
MovieClip.prototype.reversePlay = function(frameNum:Number) {
    if (frameNum > 0 && this._currentframe > 1) {
        if (this.revTimer_mc instanceof MovieClip) {
            this.revTimer_mc.removeMovieClip();
        }
        this.createEmptyMovieClip("revTimer_mc", this.getNextHighestDepth());
        
        var ref:MovieClip = this;
        var iCount:Number = 0;
        this.revTimer_mc.onEnterFrame = function() {
            ref.prevFrame();
            iCount++;
            if (iCount >= frameNum || ref._currentframe == 1) {
                delete this.onEnterFrame;
            }
        }
    }
}
Example Usage:
Code:
target_mc.reversePlay(5);
This makes the MovieClip 'target_mc' play backwards for 5 frames

Last edited by joe13; 08-02-2009 at 11:29 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
  #5  
Old 25-01-2009, 12:46 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Fading MovieClips in/out

Put the following code in the first frame of your theme:
Code:
MovieClip.prototype.fade = function(startAlpha:Number, endAlpha:Number, duration:Number) {
    if (duration > 0) {
        if (this.fadeTimer_mc instanceof MovieClip) {
            this.fadeTimer_mc.removeMovieClip();
        }
        this.createEmptyMovieClip("fadeTimer_mc", this.getNextHighestDepth());
        
        var alphaIncr:Number = Math.round((endAlpha - startAlpha)/duration);
        var ref:MovieClip = this;
        this._alpha = startAlpha; // Set initial alpha
        
        var iCount:Number = 0;
        this.fadeTimer_mc.onEnterFrame = function() {
            ref._alpha += alphaIncr;
            iCount++;
            if (iCount >= duration) {
                ref._alpha = endAlpha;
                delete this.onEnterFrame;
            }
        }
    }
}
Example Usage:
Code:
target_mc.fade(0, 100, 5);
Fades the MovieClip 'target_mc' from alpha=0 to alpha=100 in 5 frames

Last edited by joe13; 08-02-2009 at 11:29 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
  #6  
Old 25-01-2009, 12:56 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Changing Text Colors

If you want to just change the color of a text-box, use:
Code:
my_text.textColor = myColor;

//myColor needs to be a hex-decimal number in the
//format 0xNNNNNN (where N are the color numbers)
Remember to give your text-box an instance name so that you can reference it in your code.

Example Usage:
Code:
my_text.textColor = 0xFFFFFF; //White
my_text.textColor = 0x000000; //Black
This changes the colour of the text-box with the instance name 'my_text' to white and then black. Hex-decimal codes for colours can be found in most image editing programs.

Last edited by joe13; 08-02-2009 at 11:28 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
The Following User Says Thank You to joe13 For This Useful Post:
AncientDarkCall (07-09-2009)
  #7  
Old 01-02-2009, 02:12 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Displaying the Time & Date

Use a function like the following to create a clock (you can use more, or less details in your application):
Code:
function updateClock() {
    var currentDate:Date = new Date(); //Current Date-Time
    
    var dateNum:Number = currentDate.getDate(); //Date eg 21st
    //Day 0 - 6, 0 = Sunday, 1 = Monday ...
    var dayNum:Number = currentDate.getDay();
    var dayArr:Array = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");

    var dayStr:String = dayArr[dayNum];

    date_tf.text = dateNum;
    day_tf.text = dayStr;

    //You need 2 dynamic text-boxes with the instance
    //name 'date_tf' & 'day_tf'

    //You can also get the time, year & month from the date object
    var hourNum:Number = currentDate.getHours(); //Hours
    var minNum:Number = currentDate.getMinutes(); //Minutes
    var monthNum:Number = currentDate.getMonth(); //Month 0 - 11
    var yearNum:Number = currentDate.getFullYear();
}
Example Usage:
You need 2 dynamic text-boxes with the instance name 'date_tf' & 'day_tf', also
copy the updateClock method from above into your code
Code:
var clockInterval:Number;

function startClock() {
    //Update clock to begin with
    updateClock();

    var refreshTime:Number = 1000; //1 second
    clockInterval = setInterval(updateClock, refreshTime);

    //Updates clock every second
}

function stopClock() {
    clearInterval(clockInterval);
}

//Now let's start the clock
startClock();

Last edited by joe13; 08-02-2009 at 11:28 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
  #8  
Old 05-02-2009, 12:33 PM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Create a scroll-able menu

Source code & sample SWF are attached.
Attached Files
File Type: zip Scrolling List.zip (17.6 KB, 125 views)

Last edited by joe13; 08-02-2009 at 11:28 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
  #9  
Old 08-02-2009, 10:55 AM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Opening Applications or Nyx Menu Pages

Use the following function below with either a Dep or Id value (you can find these in LGAPP/Media/swf/en-UK.xml) to launch a menu page or application.

Code:
function eventCall(dep:String, id:String) {
    if (id == undefined || id == "") {
        //No id - open menu Nyx page
        platform.setMenuOn();
        _root.idleQuick = true;
        _root.QuickSet(dep);
    } else {
        //Open application
        platform.launch_module(id);
    }
};
Example usage:
Code:
eventCall("", "0x27e00000"); // Open Inbox
eventCall("3,1,1", ""); //Open browser menu page

Last edited by joe13; 08-02-2009 at 11:28 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
The Following User Says Thank You to joe13 For This Useful Post:
TomboFry (12-04-2009)
  #10  
Old 08-02-2009, 11:01 AM
Moderator
Technical Ambassador
 
Join Date: Mar 2008
Posts: 2,857
Mobile Phone: XDA Ignito, LG KU990
Network: O2
Thanks: 16
Thanked 455 Times in 69 Posts
Default Displaying the 'Touch Ring' animation

Use the following two functions to show & hide the default style 'Touch Ring' animation:

To show it at a location xPos,yPos with a scaling factor scalePercent (100 is original size):
Code:
show_pressAni(xPos:Number, yPos:Number, scalePercent:Number);
To hide the touch ring animation, simply call:
Code:
out_pressAni();
Example Usage:
Code:
my_btn.onPress = function() {
    show_pressAni(120, 200, 50);
}

my_btn.onReleaseOutside = function() {
    out_pressAni();
}

my_btn.onRelease = function() {
    out_pressAni();
    //Do something else
}
This will show the touch ring animation at the center of the screen (120, 200) at half its original size when the button "my_btn" is pressed. It then hides the animation when the button is released.

Last edited by joe13; 08-02-2009 at 11:28 AM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Share with Facebook
Closed Thread

Tags
action, actionscript, actionscript help, code, create, develop, guide, info, ku990, script, snippets, themes, viewty

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Buy a proporta case from the MyGreatPhone.com Proporta store and become a site sponsor
Similar Threads
Thread Thread Starter Forum Replies Last Post
A request to theme developers DaveOrNoDave Themes 24 17-06-2009 06:44 PM
Some questions for theme developers! bloody Themes 3 15-06-2009 12:32 PM
For Theme Developers. (attention) nestortoledo Themes 8 27-02-2008 04:09 PM
Calling all Theme Developers!!! BBman Themes 14 21-02-2008 08:09 AM


All times are GMT. The time now is 06:39 PM.

vBulletin, Copyright ©2000 - 2009
Jelsoft Enterprises Limited.

Search Engine Friendly URLs by vBSEO 3.3.1