AW: AS3 Frage (Bildergalerie)
ist zwar schon etwas her dein post aber hier die antwort vielleicht hilft sie dir ja noch...
1. tmpArray musst du außerhalb der for schleife initialisieren sonst wird es immer neu überschrieben...
2. du initialisierst ein sprite in das du dann die bilder hineinlädst ( das funktioniert genauso wie bei der xml datei)
dann lädst du die thumbs
/**
* laden eines vorschaubildes
*/
private function loadingThumb():void
{
thumbLoader=new Loader();
thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, thumbLoaded);
var fileRequest:URLRequest=new URLRequest(irgendein pfad zb: //xmlList.picture[currImage].filename);
thumbLoader.load(fileRequest);
}
/**
* wenn ein vorschaubild geladen wurde
*/
private var thumbArray:Array=[];
private var currImage=0;
private function thumbLoaded(event:Event):void
{
thumbArray.push(event.target.content);
if (currImage < xmlList.picture.length() - 1)
{
currImage++;
loadingThumb();
}
else
{
init();
}
}
private function init():void
{
//for schleife bei dem du thumbArray durchgehst und jedes anzeigst und für die verschiebung x=i*100;
}
dann nimmst du einfach diese coole scroll klasse und musst nur noch einstellen wie viel px sichtbar sein sollen
3. hier die scroll klasse (einfach in eine neue as datei kopieren)
package com.perkstoveland.utils
{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
/**
* Scroller by Perk Stoveland. March 1, 2009.
* Visit for more ActionScript goodies.
*
* You may distribute this class freely, provided it is not modified.
* ...
*
* This class takes a DisplayObject and adds a vertical scroll bar to it.
* On instanciation the class creates a mask with the height specified in
* the constuctor, and adds a scrollbar with the same height.
*
* @author: Perk Stoveland -
perk.stoveland@gmail.com
*/
public class Scroller extends Sprite
{
private const PADDING:uint = 20;
private var _scrollItem

isplayObject;
private var _masker:Sprite;
private var _scrollbarContainer:Sprite;
private var _scrollbar:Sprite;
private var _path:Sprite;
/**
* Constructor.
*
* @param $displayObject The object to be scrolled.
* @param $height [Optional] The height of the veiwable area. Default is 300 pixels.
* @param $color [Optional] The color of the scrollbar. Default is 0x555555.
*/
public function Scroller( $displayObject

isplayObject, $height:uint = 300, $color = 0x555555 )
{
_scrollItem = $displayObject;
if ( _scrollItem.parent )
{
x = _scrollItem.x;
y = _scrollItem.y;
addEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
_scrollItem.parent.addChild( this );
}
else
{
addEventListener( Event.ADDED_TO_STAGE, onAddedToStage );
}
_scrollItem.x = 0;
_scrollItem.y = 0;
addChild( _scrollItem );
createMask( $height );
createScrollbar( $color );
trace( "com.perkstoveland.utils.Scroller - Initialized\n" );
}
/**
* Places an event listener on the stage, so we make sure the
* onStopDrag() method will be called when you release the mouse
* button anywhere on the stage.
*/
private function onAddedToStage( $e:Event = null ):void
{
stage.addEventListener( MouseEvent.MOUSE_UP, onStopDrag );
}
/**
* Starts draging the scrollbar.
*/
private function onStartDrag( $e:MouseEvent ):void
{
var rect:Rectangle = new Rectangle( _path.x - ( _scrollbar.width / 2),
_path.y - ( _scrollbar.height / 2 ),
0,
_path.height );
_scrollbar.startDrag( false, rect );
addEventListener( Event.ENTER_FRAME, calculateScrollPosition );
}
/**
* Stops the dragging of the scrollbar.
*/
private function onStopDrag( $e:MouseEvent ):void
{
removeEventListener( Event.ENTER_FRAME, calculateScrollPosition );
_scrollbar.stopDrag();
}
/**
* Calculates the new position of the item being scrolled
* in relation to the draggable scrollbar.
*/
private function calculateScrollPosition( $e:Event ):void
{
var scrollbarMax:uint = _masker.height - _scrollbar.height;
var currentPos:uint = _scrollbar.y;
var percent:uint = currentPos / scrollbarMax * 100;
var scrollItemMax:uint = ( _scrollItem.height - _masker.height );
_scrollItem.y = Math.round( scrollItemMax * percent / 100 ) * -1;
}
/**
* Creates the mask.
*/
private function createMask( $height:uint ):void
{
_masker = new Sprite();
_masker.graphics.beginFill( 0xFF0000 );
_masker.graphics.drawRect( 0, 0, _scrollItem.width, $height );
_masker.graphics.endFill();
addChild( _masker );
_scrollItem.mask = _masker;
}
/**
* Creates the scrollbar
*/
private function createScrollbar( $color:uint ):void
{
_scrollbar = new Sprite();
_scrollbar.graphics.beginFill( $color );
_scrollbar.graphics.drawRoundRect( 0, 0, 7, 40, 10, 10 );
_scrollbar.graphics.endFill();
_scrollbar.addEventListener( MouseEvent.MOUSE_DOWN, onStartDrag );
_scrollbar.addEventListener( MouseEvent.MOUSE_UP, onStopDrag );
_scrollbar.buttonMode = true;
_path = new Sprite();
_path.graphics.beginFill( $color, 0.7 );
_path.graphics.drawRect( 0, 0, 1, _masker.height - _scrollbar.height );
_path.graphics.endFill();
_path.x = _scrollbar.width / 2;
_path.y = _scrollbar.height / 2;
_scrollbarContainer = new Sprite();
_scrollbarContainer.x = _masker.width + PADDING;
_scrollbarContainer.addChild( _path );
_scrollbarContainer.addChild( _scrollbar );
addChild( _scrollbarContainer );
}
}
}