Topic: Menalto Gallery G2 Widet...

Fellow Chums...

I crafted a simple widget that displays a random photo from my G2 gallery and was wondering if anybody else was interested in it.  It would have been easier just to put my pictures on Flickr - but I was too lazy to do that and spent a week learning actionscript and flash...

Also if there is interest I would be happy to put the actionscript in a post as a starting point for others. That was one of the problems I had - not enough examples to go on.

Re: Menalto Gallery G2 Widet...

Since all my stuff is in a G2 gallery, I'd love to see what you've done so far.

Thanks!

Re: Menalto Gallery G2 Widet...

Here is the actionscript that I used. There are some non-intuitive issues with getting the actual url of the picture from Gallery but it seems to work quite well.  One issue that I ran into was that you really cannot get a sized picture from gallery even if you ask for it. So I had to do the scaling on the Chumby. 

Since it is just me and you interested, if you cannont build your own .swf file I could do it for you and put your url in the program.  I havent built a configuration component since I only have one gallery myself.

/*
** set the URL from which the html will be loaded
*/

htmlURL = "http://site.com/gallery/main.php?g2_view=imageblock:External&g2_blocks=randomImage&g2_show=fullSize&g2_maxSize=320";

var my_mcl:MovieClipLoader = new MovieClipLoader();
var myListener:Object = new Object();
myListener.onLoadStart = function(target_mc:MovieClip) {
    //trace("Your load has begun on movie clip = "+target_mc);
    var loadProgress:Object = my_mcl.getProgress(target_mc);
};
myListener.onLoadProgress = function(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number) {
    percentage = Math.floor(loadedBytes/totalBytes*100);
    infoField._visible = true;
    infoField.text = percentage+"%";

};
myListener.onLoadInit = function(target_mc:MovieClip) {
    if (target_mc._width>target_mc._height) {
        target_mc._width = 320;
        target_mc._height = 240;
        target_mc._x = 0;
    } else {
        target_mc._width = 240;
        target_mc._height = 340;
        target_mc._x = target_mc._x+40;
    }
};
myListener.onLoadError = function(target_mc:MovieClip, errorCode:String) {
    infoField._visible = true;
    infoField.text = "ERROR CODE = "+errorCode;
    //trace("Your load failed on movie clip = "+target_mc+"\n");
};
my_mcl.addListener(myListener);
// Now load the files into their targets.
// loads into movie clips
this.createEmptyMovieClip("clip1_mc",this.getNextHighestDepth());

var htmlFile:XML = new XML();
htmlFile.ignoreWhite = true;
//
htmlFile.onLoad = function(success) {
    //
    infoField._visible = true;
    infoField.text = 0+"%";
    my_mcl.loadClip(htmlFile.firstChild.firstChild.firstChild.attributes.src,clip1_mc);

};

htmlFile.load(htmlURL);

4 (edited by ih8gates 2007-11-27 17:57:59)

Re: Menalto Gallery G2 Widet...

you inadvertantly just clued me in to something i'd been wondering about. i'm new to Flash and i've been getting headache dealing with instances where I need to grab data that doesn't look like "this=that&who=what". using Loadvars for this stuff works, but there are little pains to deal with. looks like XML.load is the way to go!

thanks!

Re: Menalto Gallery G2 Widet...

I am new to flash myself and I wish there were more code snippets on the site.  The XML.load was a breakthrough for me as well since I didnt want to face parsing a web page by hand.  The only thing that took me a while was the associative array when you get to the child you want.

Re: Menalto Gallery G2 Widet...

This is a easy class to use that lets you parse and read XML in Object/Array notation

http://www.sephiroth.it/file_detail.php?id=134

this rids you of all the confusing firstChild, sibling, nodeName stuff

Re: Menalto Gallery G2 Widet...

Thanks Doc, I was planning on doing exactly this and you saved me some work.  I wrapped the code up into a class that I could compile with FlashDevelop.  My main problems were with some of the nuttiness with the "this" pointer in ActionScript, compared to C++.  Anyway, if no one does it before me I'll try and hack together a config panel so this can be made public.  It sucks that pretty much all the examples posted require the ridiculously expensive Flash GUI; there need to be more pure ActionScript ones.

Re: Menalto Gallery G2 Widet...

I kind of brute forced some of the stuff - like resizing the photos to fit, etc.  If you know of anything more elegant I would be interested.  If you get the config panel done I would be interested to see it as well...

Re: Menalto Gallery G2 Widet...

Spastic - can you post the changes you've made to get the code to compile with FlashDevelop?  I'm new to flash and would like to get a widget working to view my pictures. 

Thanks Doc for posting the original example.

Re: Menalto Gallery G2 Widet...

Sorry Morgan, I saw your post a few days ago, but forgot to upload the code until now.  I just futzed around with Doc's code until I got it to load my Gallery, so this could certainly still use some work.  I couldn't figure out how to get the load progress text working, so it's basically just a blank screen until the picture pops up.

class Gallery extends Object
{
    static var htmlURL = "http://yoursite.com/main.php?g2_view=imageblock.External&g2_blocks=randomImage&g2_show=title&g2_exactSize=320";

    var timeline:MovieClip;
    var loadingClip:MovieClip;

    function onLoadStart(target_mc:MovieClip)
    {
        trace("Your load has begun on movie clip = "+target_mc);
        var loadProgress:Object = this.loadingClip.getProgress(target_mc);
    }

    function onLoadProgress(target_mc:MovieClip, loadedBytes:Number, totalBytes:Number)
    {
        var percentage = Math.floor(loadedBytes/totalBytes*100);
        trace("Progress " + percentage);

        this.timeline.infoField._visible = true;
        this.timeline.infoField.text = percentage+"%";
    }

    function onLoadInit(target_mc:MovieClip)
    {
        trace("Init");

        if (target_mc._width > target_mc._height)
        {
            target_mc._width = 320;
            target_mc._height = 240;
            target_mc._x = 0;
        }
        else
        {
            target_mc._width = 240;
            target_mc._height = 320;
            target_mc._x = target_mc._x+40;
        }
    }

    function onLoadError(target_mc:MovieClip, errorCode:String)
    {
        this.timeline.infoField._visible = true;
        this.timeline.infoField.text = "ERROR CODE = "+errorCode;
        trace("Your load failed on movie clip = "+target_mc+"\n");
    }

    function Gallery(timelineIn)
    {
        this.timeline = timelineIn;

        this.timeline.infoField._visible = true;
        this.timeline.infoField.text = "Test"

        // Now load the files into their targets.
        // loads into movie clips
        this.loadingClip = timeline.createEmptyMovieClip("my_clip", this.timeline.getNextHighestDepth());

        var owner = this;

        var htmlFile:XML = new XML();
        htmlFile.ignoreWhite = true;
        htmlFile.onLoad = function(success)
        {
            if(success)
            {
                var imgUrl = htmlFile.firstChild.firstChild.firstChild.attributes.src;
                var clipLoader = new MovieClipLoader();
                clipLoader.addListener(owner);
                clipLoader.loadClip(imgUrl, owner.loadingClip);
            }
            else
            {
                trace("Failed");
            }
        }

        htmlFile.load(htmlURL);
    }

    static function main(timeline)
    {
        var init = new Gallery(timeline);
    }
}

Re: Menalto Gallery G2 Widet...

Has anybody seen this widget get stuck on 100%?  It happens infrequently but it does and the only thing the chumby responds to is a reset.  I wonder if there is some sort of out of memory issue going on...

12 (edited by ozpaulb 2008-01-13 16:40:15)

Re: Menalto Gallery G2 Widet...

EDIT: Never mind.  I just added a unique number to the end of the URL (getTimer() - so it changes on every fetch).  This bypasses any caching done by Flash.

Is anyone else here seeing a caching issue with this widget?  When I run on my PC (via FlashDevelop), I get the same picture over and over - unless I browse to the URL with my web browser and hit Refresh (at which point the Flash widget will get the 'new' picture over and over).

When running on my Chumby, it also always retrieves the same photo over and over (although it's a different one than what was on my PC - presumably because the Chumby has cached the photo somewhere).  I also noticed that the first time I ran it on my Chumby, there was quite a delay from the start of the widget until the photo was actually loaded.  Subsequent runs are much faster (also points to a cache).

Is there any way to tell the "htmlFile" stuff to NOT use any cache? (assuming that's what I'm seeing)

Thanks,

- Paulb

13 (edited by jvc 2008-01-13 16:35:05)

Re: Menalto Gallery G2 Widet...

Try changing the line

clipLoader.loadClip(imgUrl, owner.loadingClip);

to

if(imgUrl.indexOf("?") == -1)
    {
        imgUrl+="?cachebuster="+new Date().getTime();
    }else
    {
        imgUrl+="&cachebuster="+new Date().getTime();
    }
    clipLoader.loadClip(imgUrl, owner.loadingClip);

Re: Menalto Gallery G2 Widet...

Any chance of someone putting a configuration widget and release it to the network?  I'm sure there would be a great deal of demand.

15

Re: Menalto Gallery G2 Widet...

rstocks did you see this one?

http://wiki.chumby.com/mediawiki/index. … ner_Widget

Re: Menalto Gallery G2 Widet...

jvc,

Yes, I've seen the developer stuff.  However, whilst a huge fan and user of open source software, a developer I'm not :-)  I've told the wife she needs to find herself a Flash toolchain and start learning it :-D

I stand by my original comment - I'm sure there are a bunch of people who use Gallery who either haven't found this thread or haven't seen the light and got their hands on a Chumby yet.  If someone would wrap a configuration widget around this and post it to the Chumby network I'm sure you'd see it in the top ten list pretty quick.

Cheers,

R.

Re: Menalto Gallery G2 Widet...

rstocks - I will see if I can get some time and craft a configuration widget for Gallery this weekend.

Re: Menalto Gallery G2 Widet...

Hey, I got the configuration completed for Doc, and have given it to him. So, hopefully soon he will upload it to the public!

My chumby is in the mail!

Re: Menalto Gallery G2 Widet...

Thanks to dattas we now have a configurable gallery widget.  It is now been upload and made public.  Let me know how it works for you guys.

Re: Menalto Gallery G2 Widet...

You guys rock!  I'm away from home at the moment, but I'm going to add it and see what happens (and if my wife notices!)

Re: Menalto Gallery G2 Widet...

This is a bit weird - it dosn't seem to work right on the virtual chumby - but it works like a champ on the real one... i am not sure what that is all about.

Re: Menalto Gallery G2 Widet...

Thanks Doc for keeping up the work! Think I'm going to have to switch to Menalto now smile

Re: Menalto Gallery G2 Widet...

DocSavage wrote:

This is a bit weird - it dosn't seem to work right on the virtual chumby - but it works like a champ on the real one... i am not sure what that is all about.

Just noticed that myself... my Chumby is a good 4000 miles away from me at the moment, so I was looking for a virtual fix :-)

Re: Menalto Gallery G2 Widet...

Well - even stranger, i thought maybe there is some caching issue with the flash, so I fired up FireFox and it works great in the Virtual Chumby.  So at least it dosnt seem to be a bug in the widget.  I noticed also that some of the other widgets were acting strange in the Virtual Chumby under Internet Explorer as well.

Re: Menalto Gallery G2 Widet...

No such luck for me... just tried the virtual Chumby under Firefox and no go.  But as long as it works on the real one, I don't care :-)