Stripping Netstream Into Function
hi all - got a question that is making my brain ache now!
i have this script that sets up and connects a stream to play an flv - in the case using xml to define where the flv is...
PHP Code:
private function onInitialize():void
{
_connection = new NetConnection();
_connection.addEventListener(NetStatusEvent.NET_STATUS, onConnectionNetStatus, false, 0, true);
_connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onConnectionError, false, 0, true);
_connection.addEventListener(AsyncErrorEvent.ASYNC_ERROR, onConnectionError, false, 0, true);
_connection.addEventListener(IOErrorEvent.IO_ERROR, onConnectionError, false, 0, true);
_connection.objectEncoding = ObjectEncoding.DEFAULT;
_connection.client = {
onBWDone: onBWDone
};
//_connection.connect("rtmp://yourfmshere/");
_connection.connect(null);
}
private function onConnectionError(...args):void
{
trace("Test.onConnectionError()");
}
private function onConnectionNetStatus(event:NetStatusEvent):void
{
var debug:Object = event.info;
var sT:SoundTransform;
trace("**** code **** " + event.info.code);
switch (event.info.code)
{
case "NetConnection.Connect.Success":
_stream = new NetStream(_connection);
_stream.client = {
onMetaData: onMetaData,
onCuePoint: onCuePoint
};
_video = new Video();
_video.attachNetStream(_stream);
_stream.play(videoPath +
addChild(_video);
var xscaler:Number = (1 / _video.width) * stage.stageWidth;
var yscaler:Number = (1 / _video.width) * stage.stageHeight;
_video.scaleX = xscaler;
_video.scaleY = yscaler;
break;
case "NetConnection.Connect.Closed":
trace("closed");
break;
/* Fatal errors */
case "NetConnection.Connect.Rejected":
case "NetConnection.Connect.Failed":
break;
default:
break;
}
}
private function onBWDone(...args):void
{
trace("Test.onBWDone()");
}
private function onMetaData(...args):void
{
trace("Test.onMetaData()");
_metaData = args[0];
}
private function onCuePoint(...args):void
{
trace("Test.onCuePoint()");
}
private function onUpdateTimer(event:TimerEvent):void
{
trace("Test.onUpdateTimer()");
trace(" "+_stream.bytesLoaded+" of "+_stream.bytesTotal+" bytes loaded.");
trace(" "+_stream.time+" of "+_metaData.duration+" played.");
trace(" _stream.bufferLength:"+_stream.bufferLength);
if (_stream.time >= _metaData.duration)
{
_updateTimer.removeEventListener(TimerEvent.TIMER, onUpdateTimer);
_updateTimer = null;
}
}
it works and works well - no controls but that is okay for now
what I am trying to do but am failing miserably is to strip the code above into this function very long sorry - but essentially it creates the largeimage or flv - and also shows previous and next buttons.
PHP Code:
/**
* FUNCTION
* _______________________________________________________________________________________________________________________________________
*
* show large image.
* @param none
*
*/
private function showLargeImage():void
{
/**
* fade in controlpanel.
*
*/
Tweener.addTween(panel, { _autoAlpha:1, time:0.5, delay:1.5 } );
/**
* get large image instance as bitmap from loader queue.
*
*/
largeImage = largeImageLoader.getBitmap("largeimage") as Bitmap;
/**
* calculate image size for scaling images.
*
*/
var xscaler:Number = (1 / largeImage.width) * stage.stageWidth;
largeImage.scaleX = xscaler;
largeImage.scaleY = xscaler;
/**
* create new zoom container instance.
*
*/
zoomContainer = new Sprite;
/**
* hide zoom container on startup.
*
*/
Tweener.addTween(zoomContainer, { _autoAlpha:0, time:0 } );
/**
* create new pan container instance.
*
*/
panContainer = new Sprite;
/**
* add zoom container instance to displaylist.
*
*/
viewport.addChild(zoomContainer);
/**
* position pan container.
*
*/
panContainer.x = zoomContainer.width / 2;
panContainer.y = zoomContainer.height / 2;
/**
* position large image.
*
*/
largeImage.x = largeImage.width / 2 * -1;
largeImage.y = largeImage.height / 2 * -1;
/**
* position zoom container centered on stage.
*
*/
zoomContainer.x = int((stage.stageWidth - zoomContainer.width) * 0.5);
zoomContainer.y = int((stage.stageHeight - zoomContainer.height) * 0.5);
/**
* add pan container to zoom container instance.
*
*/
zoomContainer.addChild(panContainer);
/**
* add large image to pan container instance.
*
*/
panContainer.addChild(largeImage);
/**
* create new image info container instance.
*
*/
imageInfoBoxContainer = new Sprite();
/**
* hide image info container on startup.
*
*/
Tweener.addTween(imageInfoBoxContainer, { _autoAlpha:0, time:0 } );
/**
* position image info container top left on stage.
*
*/
imageInfoBoxContainer.x = int((stage.stageWidth - 400) * 0.5);
imageInfoBoxContainer.y = int((stage.stageHeight - 300) * 0.5);
/**
* add image info container to displaylist.
*
*/
addChild(imageInfoBoxContainer);
/**
* create new imageInfoBox instance.
*
*/
imageInfoBox = new ImageWorld3dItemInfoBox(0x000000, 0.65, 0xFFFFFF, 0xCCCCCC);
/**
* add info to image info box.
*
*/
imageInfoBox.addInfo(imageArray[largeImageItem].infotitle, imageArray[largeImageItem].infotext);
/**
* add image info infobox instance to image info container instance.
*
*/
imageInfoBoxContainer.addChild(imageInfoBox);
/**
* add mouse down event to pan container for dragging image.
*
*/
panContainer.addEventListener(MouseEvent.MOUSE_DOWN, moveLargeImage, false, 0, true);
/**
* add stage eventlistener on mouse up to stop dragging large image.
*
*/
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragLargeImage, false, 0, true);
/**
* add eventlistener to stage for zooming large image.
*
*/
stage.addEventListener(MouseEvent.MOUSE_WHEEL, zoomLargeImage, false, 0, true);
/**
* fade in zoom container.
*
*/
Tweener.addTween(zoomContainer, { _autoAlpha:1, time:1, delay:1 } );
/**
* check if auto show description is set to true and display description automatically
*
*/
if (autoShowImageDescription == 1)
{
Tweener.addTween(imageInfoBoxContainer, { _autoAlpha:1, time:1, delay:2.5 } );
imageDescriptionShowStatus = true;
}
/**
* create new thumbnav instance.
*
*/
nextThumbnailContainer = new Nextthumb();
/**
* set thumbnav button mode.
*
*/
nextThumbnailContainer.buttonMode = true;
/**
* fade in thumbnav with delay.
*
*/
Tweener.addTween(nextThumbnailContainer, { _autoAlpha: 0, time: 0 } );
Tweener.addTween(nextThumbnailContainer, { _autoAlpha: 1, time: 0.5, delay:2 } );
/**
* create new thumbnav image container instance.
*
*/
nextThumbnailImageContainer = nextThumbnailContainer.getChildByName("nextthumbholder") as Sprite;
/**
* set next thumbnav item number.
*
*/
nextThumbnailImageNumber = Number(largeImageItem) + 1;
/**
* calculate next item proper.
*
*/
if (nextThumbnailImageNumber == imageAmount)
{
nextThumbnailImageNumber = 0;
}
/**
* create new thumbnav image instance.
*
*/
nextThumbnailImage = new Bitmap();
/**
* get thumbnav image from loader.
*
*/
nextThumbnailImage = imagesloader.getBitmap("thumbnail" + nextThumbnailImageNumber) as Bitmap
/**
* set thumbnav image alpha for startupü.
*
*/
nextThumbnailImage.alpha = 0.5;
/**
* add thumbnav image to thumbnav container.
*
*/
nextThumbnailImageContainer.addChild(nextThumbnailImage);
/**
* position thumbnav image.
*
*/
nextThumbnailImage.x = (nextThumbnailImageContainer.width - nextThumbnailImage.width) * 0.5;
nextThumbnailImage.y = (nextThumbnailImageContainer.height - nextThumbnailImage.height) * 0.5;
/**
* position thumbnav container on stage.
*
*/
nextThumbnailContainer.x = int(stage.stageWidth - 10);
nextThumbnailContainer.y = int((stage.stageHeight - 76) * 0.5);
/**
* add thumbnav container to displaylist.
*
*/
addChild(nextThumbnailContainer);
/**
* add eventlisteners to next thumbnav container.
*
*/
nextThumbnailContainer.addEventListener(MouseEvent.CLICK, loadNextImage, false, 0, true);
nextThumbnailContainer.addEventListener(MouseEvent.ROLL_OVER, showNextImage, false, 0, true);
nextThumbnailContainer.addEventListener(MouseEvent.ROLL_OUT, hideNextImage, false, 0, true);
/**
* create new thumbnav instance.
*
*/
prevThumbnailContainer = new Nextthumb();
/**
* set thumbnav button mode.
*
*/
prevThumbnailContainer.buttonMode = true;
/**
* fade in thumbnav with delay.
*
*/
Tweener.addTween(prevThumbnailContainer, { _autoAlpha: 0, time: 0 } );
Tweener.addTween(prevThumbnailContainer, { _autoAlpha: 1, time: 0.5, delay:2 } );
/**
* create new thumbnav image container instance.
*
*/
prevThumbnailImageContainer = prevThumbnailContainer.getChildByName("nextthumbholder") as Sprite;
/**
* set next thumbnav item number.
*
*/
prevThumbnailImageNumber = Number(largeImageItem) - 1;
/**
* calculate prev item proper.
*
*/
if (prevThumbnailImageNumber < 0)
{
prevThumbnailImageNumber = imageAmount - 1;
}
/**
* create new thumbnav image instance.
*
*/
prevThumbnailImage = new Bitmap();
/**
* get thumbnav image from loader.
*
*/
prevThumbnailImage = imagesloader.getBitmap("thumbnail" + prevThumbnailImageNumber) as Bitmap
/**
* set thumbnav image alpha for startup
*
*/
prevThumbnailImage.alpha = 0.5;
/**
* add thumbnav image to thumbnav container.
*
*/
prevThumbnailImageContainer.addChild(prevThumbnailImage);
/**
* position thumbnav image.
*
*/
prevThumbnailImage.x = (prevThumbnailImageContainer.width - prevThumbnailImage.width) * 0.5;
prevThumbnailImage.y = (prevThumbnailImageContainer.height - prevThumbnailImage.height) * 0.5;
/**
* position thumbnac container on stage.
*
*/
prevThumbnailContainer.x = -66;
prevThumbnailContainer.y = int((stage.stageHeight - 76) * 0.5);
/**
* add thumbnav container to displaylist.
*
*/
addChild(prevThumbnailContainer);
/**
* add eventlisteners to thumbnav container.
*
*/
prevThumbnailContainer.addEventListener(MouseEvent.CLICK, loadPrevImage, false, 0, true);
prevThumbnailContainer.addEventListener(MouseEvent.ROLL_OVER, showPrevImage, false, 0, true);
prevThumbnailContainer.addEventListener(MouseEvent.ROLL_OUT, hidePrevImage, false, 0, true);
}
is it something simple and i'm just being a doughnut - or is it not very straight forward?
anyone help me please?