Skip to main content
Known Participant
October 29, 2009
Answered

Image previewArea on mouse over

  • October 29, 2009
  • 3 replies
  • 4405 views

I am trying mouseover a thumbnail to show another image somewhere else in the flash document. I'll put the coding in a quote and post the error I'm getting. I appear to be having problems IDing the 'previewArea' movieclip.

http://i612.photobucket.com/albums/tt207/rotdoombot/errors2.jpg

function previewLoaded(e:Event):void
{

trace(this);
trace(this.getChildByName('previewArea');
    while(previewArea.numChildren){ previewArea.removeChildAt(0); };
    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content);
    flashmo_tn_bm.smoothing = true;
    previewArea.addChild(flashmo_tn_bm);
   
}

Thank you for your help.

This topic has been closed for replies.
Correct answer Kalisto

function previewLoaded(e:Event):void {


    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content);

    flashmo_tn_bm.smoothing = true;


    var previewArea:MovieClip = new MovieClip();
    previewArea.name = "previewArea";

    previewArea.addChild(flashmo_tn_bm);


    addChild(previewArea);

}

I'll show you an image of my problem. I think you'll understand the problem now.

http://i612.photobucket.com/albums/tt207/rotdoombot/loadwrong.jpg


set x and y pos of previewArea

3 replies

Known Participant
October 30, 2009

Thanks for your help but I still don't get any imagery in the previewArea

function previewLoaded(e:Event):void
{
   
    previewArea.name = "previewArea"
    var previewArea:MovieClip = new MovieClip();
    previewArea.addChild(flashmo_tn_bm);
    previewArea.addChild(previewArea);
    getChildByName( "previewArea" )
    while (previewArea.numChildren) { previewArea.removeChildAt(0); };
    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content);
    flashmo_tn_bm.smoothing = true;
   
}


Is what I did and nothing changed. The only other area I could see there being a problem is.

function tn_over(e:MouseEvent):void
{
    var mc:MovieClip = MovieClip(e.target);
    current_no = parseInt(mc.name.slice(11,13));
    Tweener.addTween( mc, { alpha: 0.5, time: tween_duration, transition: "easeIn" } );
   
    link_title.text = flashmo_tn_list[current_no].title;
    link_description.text = flashmo_tn_list[current_no].description;
   
    var pic_request:URLRequest = new URLRequest('fullpreviewimages/' + flashmo_tn_list[current_no].filename );
    var pic_loader:Loader = new Loader();


    pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, previewLoaded);
    pic_loader.load(pic_request);
}

When I mouse over the thumbnail maybe it just won't load the image list. Thanks to everyone for the help but this problem just seems to refuse to get fixed.

Inspiring
October 30, 2009

Let look closer this:

function previewLoaded(e:Event):void
{
   
    previewArea.name = "previewArea"          <- Is the previewArea variable declared outside of this function? If it is this row is OK, but!


    var previewArea:MovieClip = new MovieClip(); <- Here you declare previewArea If you have variable declared outside of this function this is a conflict with the names. If you haven't class member variable with this name than above row must be setted after this row ( It is a good coding practise;


    previewArea.addChild(flashmo_tn_bm); <- It is OK


    previewArea.addChild(previewArea); <- You adding into previewArea the previewArea It is a recursion you cannot add clip inside himself


    getChildByName( "previewArea" ) <- getChildByName return a reference to displayObejct with this name, but you don't handle this name. This row has no means and the compiler may ignore it.

  usage of getChildByName  is this: var dispObject: DisplayObject = getChildByName( "SomeName" ); In your case  getChildByName( "previewArea" ) returns previewArea  but already have this variable here


    while (previewArea.numChildren) { previewArea.removeChildAt(0); }; You remove all content into previewArea


    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content); <- again variable definition is here but this variable is used above.
    flashmo_tn_bm.smoothing = true;
   
}

you must use something like this:

function previewLoaded(e:Event):void
{

    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content); // Create a bitmap from the content of the loader

     flashmo_tn_bm.smoothing = true;


    var previewArea:MovieClip = new MovieClip(); // Create a holder for the content


    previewArea.name = "previewArea" // Naming the holder
   
    previewArea.addChild(flashmo_tn_bm); // Add bitmap to the holder
    addChild(previewArea); // Add holder to the stage

// And what this must do?
    while (previewArea.numChildren)

     { previewArea.removeChildAt(0); }; // This remove all elements from previewArea so after this teh previeArea is empty clip.Are you sure that you want this?

Known Participant
October 30, 2009

function previewLoaded(e:Event):void
{

    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content);

     flashmo_tn_bm.smoothing = true;
    
     previewArea.name = "previewArea"

    var previewArea:MovieClip = new MovieClip();
    var dispObject: DisplayObject = getChildByName( "previewArea" );

    previewArea.addChild(flashmo_tn_bm);
    addChild(previewArea);


    while (previewArea.numChildren)

     { previewArea.removeChildAt(0); };
}

If I use that coding and change  { previewArea.removeChildAt(0); }; to something like  { previewArea.removeChildAt(1); }; once I mouse over an area the first slide of the thumbnail changes into the preview images that I want. I think we are almost there. I just need to find a way to not have it load inside of the thumbnail slider and into the previewArea.

Known Participant
October 30, 2009

function previewLoaded(e:Event):void
{

var previewArea:MovieClip = new MovieClip();
previewArea.addChild(flashmo_tn_bm);
trace(this);
trace(this.getChildByName('previewArea'));
while (previewArea.numChildren) { previewArea.removeChildAt(0); };
var flashmo_tn_bm:Bitmap = Bitmap(e.target.content);
flashmo_tn_bm.smoothing = true;
var pic_request:URLRequest = new URLRequest('fullpreviewimages/' + flashmo_tn_list[current_no].filename );
var pic_loader:Loader = new Loader();
}

Is the coding I have no. It will still not show any images in previewArea though.

October 30, 2009

when you load the image can i see you on complete code?

This cody you posted by the way never loads anything

var pic_request:URLRequest = new URLRequest('fullpreviewimages/' + flashmo_tn_list[current_no].filename );
var pic_loader:Loader = new Loader();

you need to

pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onLoadComplete)

pic_loader.load(pic_request)

Known Participant
October 30, 2009

Here is the full code. It's very long.. But I did what you said but it doesn't says that it doesn't recognize the previewArea then

import caurina.transitions.Tweener;

slider_info.text = "loading data...";
link_title.text = "";
link_description.text = "";

var folder:String = "thumbnails/";
var start_from:Number = 0;
var no_of_tn:Number = 5;
var i:Number;
var tn:Number = 0;
var current_no:Number = 0;
var tween_duration:Number = 0.8;    // seconds
var total:Number;
var flashmo_xml:XML;
var flashmo_tn_list = new Array();
var thumbnail_group:MovieClip = new MovieClip();


this.addChild(thumbnail_group);
thumbnail_group.mask = slider_mask;

function load_gallery(xml_file:String):void
{
    var xml_loader:URLLoader = new URLLoader();
    xml_loader.load( new URLRequest( xml_file ) );
    xml_loader.addEventListener(Event.COMPLETE, create_thunbnail_slider);
}

function create_thunbnail_slider(e:Event):void
{
    flashmo_xml = new XML(e.target.data);
    total = flashmo_xml.thumbnail.length();

    for( i = 0; i < total; i++ )
    {
        flashmo_tn_list.push( {
            filename: flashmo_xml.thumbnail.filename.toString(),
            title: flashmo_xml.thumbnail.title.toString(),
            description: flashmo_xml.thumbnail.description.toString(),
            url: flashmo_xml.thumbnail.url.toString(),
            target: flashmo_xml.thumbnail.target.toString()
        } );
    }
    load_tn();
}

function load_tn():void
{
    var pic_request:URLRequest = new URLRequest( folder + flashmo_tn_list[tn].filename );
    var pic_loader:Loader = new Loader();
   
    pic_loader.load(pic_request);
    pic_loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, tn_progress);
    pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, tn_loaded);
    tn++;
}

function tn_progress(e:ProgressEvent):void
{
    slider_info.text = "loading thumbnail... " + tn + " of " + total;
}

function tn_loaded(e:Event):void
{
    if( tn < total )
        load_tn();
    else
        slider_info.text = "";

    var flashmo_tn_bm:Bitmap = new Bitmap();
    var flashmo_tn_mc:MovieClip = new MovieClip();
   
    flashmo_tn_bm = Bitmap(e.target.content);
    flashmo_tn_bm.smoothing = true;
   
    flashmo_tn_mc.addChild(flashmo_tn_bm);
    flashmo_tn_mc.name = "flashmo_tn_" + thumbnail_group.numChildren;
    flashmo_tn_mc.buttonMode = true;
    flashmo_tn_mc.addEventListener( MouseEvent.MOUSE_OVER, tn_over );
    flashmo_tn_mc.addEventListener( MouseEvent.MOUSE_OUT, tn_out );
    flashmo_tn_mc.addEventListener( MouseEvent.CLICK, tn_click );
    flashmo_tn_mc.x = thumbnail_group.numChildren * 150;
   
    thumbnail_group.addChild( flashmo_tn_mc );
}
function previewLoaded(e:Event):void
{
   
    var previewArea:MovieClip = new MovieClip();
    previewArea.addChild(flashmo_tn_bm);
    trace(this);
    trace(this.getChildByName('previewArea'));
    while (previewArea.numChildren) { previewArea.removeChildAt(0); };
    var flashmo_tn_bm:Bitmap = Bitmap(e.target.content);
    flashmo_tn_bm.smoothing = true;
    var pic_request:URLRequest = new URLRequest('fullpreviewimages/' + flashmo_tn_list[current_no].filename );
    var pic_loader:Loader = new Loader();
}

function tn_over(e:MouseEvent):void
{
    var mc:MovieClip = MovieClip(e.target);
    current_no = parseInt(mc.name.slice(11,13));
    Tweener.addTween( mc, { alpha: 0.5, time: tween_duration, transition: "easeIn" } );
   
    link_title.text = flashmo_tn_list[current_no].title;
    link_description.text = flashmo_tn_list[current_no].description;
   
    var pic_request:URLRequest = new URLRequest('fullpreviewimages/' + flashmo_tn_list[current_no].filename );
    var pic_loader:Loader = new Loader();

    pic_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, previewLoaded);
    pic_loader.load(pic_request);
}

function tn_out(e:MouseEvent):void
{
    var mc:MovieClip = MovieClip(e.target);
    current_no = parseInt(mc.name.slice(11,13));
    Tweener.addTween( mc, { alpha: 1, time: tween_duration, transition: "easeOut" } );
   
    link_title.text = "";
    link_description.text = "";
}

function tn_click(e:MouseEvent):void
{
    var mc:MovieClip = MovieClip(e.target);
    current_no = parseInt(mc.name.slice(11,13));
    navigateToURL( new URLRequest( flashmo_tn_list[current_no].url ),
                                flashmo_tn_list[current_no].target );
}

function move_slider():void
{
    if( total - start_from < no_of_tn )
        start_from = total - no_of_tn;
    if( start_from < 0 )
        start_from = 0;
       
    Tweener.addTween( thumbnail_group, { x: - start_from * 150,
                      time: tween_duration, transition: "easeInOutQuart" } );
}

flashmo_previous.addEventListener( MouseEvent.CLICK, move_left );
flashmo_next.addEventListener( MouseEvent.CLICK, move_right );

function move_left(e:MouseEvent):void
{
    start_from -= no_of_tn;
    move_slider();
}

function move_right(e:MouseEvent):void
{
    start_from += no_of_tn;
    move_slider();
}

Inspiring
October 29, 2009

You miss the secont ")". First closes the getChildByName and second close trace method

trace( this.getChildByName( 'previewArea' ) );

Known Participant
October 29, 2009

Thank you that helps but then I get another error! Let me show you.http://i612.photobucket.com/albums/tt207/rotdoombot/error3.jpg

It appears that it is not understanding the previewArea movieclip I have on stage.