[19. April 2013] A-400 Advanced Network Setup now available | [11 Jan. 2013] Customize your A-400 Home Screen

Firmware: A-400 [13 May 2013] | C-300 [30 Nov. 2012] | A-300 [30 Nov. 2012] | C-200 [21 Jan. 2013] | A-200/A-210 [10 Aug. 2012]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Post Reply 
[300] Webservices in flash
07-23-2012, 04:38 AM (This post was last modified: 07-24-2012 04:08 AM by rolandhii.)
Post: #1
Webservices in flash
Due to the webservices HTML page in 200-series players is no longer shown in 300-series, I decided to write this little flash app to show the contents of webservices in flash UI.

Since I am a beginner in flash programming, I have decided to open the source code here so that other people can help in improving this little app.

This is written using FlashDevelop following Steve's nice example here: [FLASH] Development

PHP Code:
/**
 * ...
 * @author Roland Hii
 */
class Main {
    static var 
webServices:Array = new Array();
    static var 
highlightMC:MovieClip null;
    static var 
selectedColumn:Number 0;
    static var 
selectedIndex:Number 0;
    static var 
selectedRow:Number 0;
    static var 
infoTF:TextField null;

    static var 
parentMC:MovieClip null;
    static var 
firstCellX:Number 0;
    static var 
firstCellY:Number 0;
    static var 
center24Format:TextFormat null;
    static var 
left14Format:TextFormat null;

    
// Constants.
    
static var CELL_HEIGHT:Number 98;
    static var 
CELL_WIDTH:Number 132;
    static var 
HIGHLIGHT_OFFSET_X:Number = -14;
    static var 
HIGHLIGHT_OFFSET_Y:Number = -34;
    static var 
NUM_OF_COLS:Number 8;
    static var 
NUM_OF_ROWS:Number 4;
    static var 
SCREEN_HEIGHT_SAFE:Number 656;
    static var 
SCREEN_WIDTH_SAFE:Number 1100;

    public static function 
main(swfRoot:MovieClip):Void {
        
// Entry point.
        
parentMC swfRoot;

        
// Make sure the stage is set to 1280x720.
        
firstCellX = (Stage.width SCREEN_WIDTH_SAFE) / 2;
        
firstCellY = (Stage.height SCREEN_HEIGHT_SAFE) / 2;

        
center24Format = new TextFormat();
        
center24Format.align "center";
        
center24Format.size 24;

        
left14Format = new TextFormat();
        
left14Format.align "left";
        
left14Format.size 14;

        
// Register listeners.
        
var keyListener:Object = new Object();
        
keyListener.onKeyDown klOnKeyDownCB;
        
Key.addListener(keyListener);

        
// Load the page to retrieve the list of webservices installed.
        
var lv:LoadVars = new LoadVars();
        
lv.onData lvOnDataCB;
        
lv.load("http://127.0.0.1:8883/webservices.cgi");
    }

    private static function 
klOnKeyDownCB():Void {
        switch (
Key.getCode()) {
            case 
Key.ENTER:
                if (
webServices[selectedIndex].link != null) {
                    var 
lv:LoadVars = new LoadVars();
                    
lv.onData lvOnDataKeyEnterCB;
                    
lv.load(webServices[selectedIndex].link);
                    
infoTF.text "Loading '" webServices[selectedIndex].link "'...\n";
                }
                break;
            case 
Key.UP:
                if (
selectedRow 0) {
                    
selectedRow--;
                    
selectedIndex -= NUM_OF_COLS;
                    
highlightMC._y firstCellY HIGHLIGHT_OFFSET_Y + (selectedRow CELL_HEIGHT);
                    
showSelectedTitle(selectedIndex);
                }
                break;
            case 
Key.DOWN:
                if (
selectedRow < (NUM_OF_ROWS 1)) {
                    
selectedRow++;
                    
selectedIndex += NUM_OF_COLS;
                    
highlightMC._y firstCellY HIGHLIGHT_OFFSET_Y + (selectedRow CELL_HEIGHT);
                    
showSelectedTitle(selectedIndex);
                }
                break;
            case 
Key.LEFT:
                if (
selectedColumn 0) {
                    
selectedColumn--;
                    
selectedIndex--;
                    
highlightMC._x firstCellX HIGHLIGHT_OFFSET_X + (selectedColumn CELL_WIDTH);
                    
showSelectedTitle(selectedIndex);
                }
                break;
            case 
Key.RIGHT:
                if (
selectedColumn < (NUM_OF_COLS 1)) {
                    
selectedColumn++;
                    
selectedIndex++;
                    
highlightMC._x firstCellX HIGHLIGHT_OFFSET_X + (selectedColumn CELL_WIDTH);
                    
showSelectedTitle(selectedIndex);
                }
                break;
        }
    }

    private static function 
lvOnDataCB(src:String):Void {
        if (
src == undefined) {
            
trace("Error loading content.");
            return;
        }

        
// Draw background.
        
var bg:MovieClip parentMC.createEmptyMovieClip("bg"parentMC.getNextHighestDepth());
        
bg._x 0;
        
bg._y 0;
        
bg.loadMovie(src.split('<body file background="')[1].split('"')[0]);

        
// Find all webservices installed.
        
var hrefList:Array = src.split('<a href="');
        var 
length:Number hrefList.length;
        
// First item is the part before delimiter, ignore it.
        
for (var 1lengthi++) {
            var 
href:String hrefList[i].split('"')[0];
            if (
href != "file:///opt/sybhttpd/default/webservices_edit.html") {
                if ((
href == "#") ||
                    (
href == "file:///opt/syb/local/appcenter/index.phf") ||
                    (
href == "http://127.0.0.1:8883/torrent/bt.cgi") ||
                    (
href.indexOf("http://www.mspportal.com/") >= 0)) {
                    
href null;
                }

                
webServices.push({
                    
link:href,
                    
title:hrefList[i].split('fip="')[1].split('"')[0],
                    
thumbnail:hrefList[i].split('<img src="')[1].split('"')[0]
                });
            }
        }

        
// Draw table.
        
var c:Number 0;
        var 
r:Number 0;
        
length webServices.length;
        for (var 
0lengthi++) {
            var 
thumbnail:MovieClip parentMC.createEmptyMovieClip("thumbnail" iparentMC.getNextHighestDepth());
            
thumbnail._x firstCellX + (CELL_WIDTH);
            
thumbnail._y firstCellY + (CELL_HEIGHT);
            
thumbnail.loadMovie(webServices[i].thumbnail);

            if (++
>= NUM_OF_COLS) {
                
0;
                ++
r;
            }
        }

        
// Get the highlight thumbnail (in the last IMG tag).
        
var lastIndex:Number src.lastIndexOf('<img src="') + '<img src="'.length;
        
highlightMC parentMC.createEmptyMovieClip("highlight"parentMC.getNextHighestDepth());
        
highlightMC.loadMovie(src.substring(lastIndexsrc.indexOf('"'lastIndex)));

        
// Set default highlight to the first item.
        
highlightMC._x firstCellX HIGHLIGHT_OFFSET_X;
        
highlightMC._y firstCellY HIGHLIGHT_OFFSET_Y;
        
selectedColumn 0;
        
selectedRow 0;
        
selectedIndex 0;

        
// Create text field to show some info.
        
infoTF parentMC.createTextField("infoTF"parentMC.getNextHighestDepth(), firstCellXfirstCellY + (NUM_OF_ROWS CELL_HEIGHT),
                                          
SCREEN_WIDTH_SAFESCREEN_HEIGHT_SAFE - (firstCellY + (NUM_OF_ROWS CELL_HEIGHT)));
        
infoTF.autoSize "left";
        
infoTF.background false;
        
infoTF.backgroundColor 0;
        
infoTF.html true;
        
infoTF.multiline true;
        
infoTF.textColor 0xFFFFFF;
        
infoTF.wordWrap true;
        
infoTF.setNewTextFormat(center24Format);

        
showSelectedTitle(selectedIndex);
    }

    private static function 
lvOnDataKeyEnterCB(src:String):Void {
        
infoTF.background true;
        
infoTF.setNewTextFormat(left14Format);
        if (
src == undefined) {
            
infoTF.text += "Error loading content.\n";
        } else {
            
// Print the output without HTML tags.
            
infoTF.htmlText src;
        }
        
infoTF.setNewTextFormat(center24Format);
    }

    private static function 
showSelectedTitle(index:Number):Void {
        
infoTF.background false;
        
infoTF.textColor = (webServices[index].link == null) ? 0x444444 0xFFFFFF;
        
infoTF.text = (index 1) + "/" webServices.length ": " webServices[index].title;
    }


Hope this is useful. Any feedbacks are welcome!

Edit: Added screenshots and attached the compiled binary.

[Image: 70e5f34cb06589db0b6b_1.jpg] [Image: 70e5f34cb06589db0b6b_2.jpg] [Image: 70e5f34cb06589db0b6b_3.jpg] [Image: 70e5f34cb06589db0b6b_4.jpg]


Attached File(s)
.zip  Webservices.zip (Size: 2.02 KB / Downloads: 19)
Find all posts by this user
Add Thank You Quote this message in a reply
[+] 5 users say Thank You to rolandhii for this post
07-23-2012, 04:59 AM
Post: #2
RE: Webservices in flash
good starter project.

Something I wanted to do but ended up heading a different direction for my stuff was to take a couple still maintained existing libraries for flashlite to extend text clips. They add javascript and tables to existing flash html support. Shouldn't be too hard to further extend them for tvid and playback support and should do more than gaya does today. not really going to offer a full on browser but should fully support all the gaya interfaces out now and add in XHR support.
Find all posts by this user
Add Thank You Quote this message in a reply
07-24-2012, 04:10 AM
Post: #3
RE: Webservices in flash
Added screenshots and attached the compiled binary.
Find all posts by this user
Add Thank You Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [300] Kroozbox flash based - any takers? Nono 29 3,504 02-13-2013 04:14 PM
Last Post: Nono
  [300] Displaying flash from website? narubonk 11 2,186 09-05-2012 05:20 AM
Last Post: accident
  [300] No flash needed flash apps. accident 2 1,315 02-28-2012 06:38 AM
Last Post: rubbers
  [300] flash apps george7523 3 1,190 02-14-2012 01:28 AM
Last Post: accident
  [300] [FLASH Apps] Forex Parity POPA110 2 1,665 02-13-2012 05:20 AM
Last Post: chris57
  [200] [FLASH Apps] Project XMC Steve007 21 3,882 11-10-2011 12:26 PM
Last Post: Pernod
  [300] [FLASH] Development Steve007 13 6,113 11-06-2011 02:56 PM
Last Post: bdwillie
  [200] SwissCenter with Flash Pernod 6 1,469 11-06-2011 05:04 AM
Last Post: accident
  [200] [Apps] Run CGI script from flash zofer 5 2,492 03-24-2011 11:04 AM
Last Post: zofer
  [200] Opera & Flash player coming to Xtreamer. C200?? cerk2006 7 5,176 09-15-2010 01:53 PM
Last Post: Adrgha

Forum Jump: