as3 - rewrite this line?
- Started
- Last post
- 20 Responses
- wwfc
howdee! still tying to get to grips with as3 - so please forgive yet another question 'bout it!
okay how can i rewrite this line of script:
largeImage = largeImageLoader.getBitmap("larg... as Bitmap;
to call in the netstream video that i have created here:
private function onInitialize():void
{
_connection = new NetConnection();
_connection.addEventListener(Net... onConnectionNetStatus, false, 0, true);
_connection.addEventListener(Sec... onConnectionError, false, 0, true);
_connection.addEventListener(Asy... onConnectionError, false, 0, true);
_connection.addEventListener(IOE... onConnectionError, false, 0, true);
_connection.objectEncoding = ObjectEncoding.DEFAULT;
_connection.client = {
onBWDone: onBWDone
};
//_connection.connect("rtmp://yo...
_connection.connect(null);
}private function onConnectionError(...args):void
{
trace("Test.onConnectionError...
}private function onConnectionNetStatus(event:NetS...
{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...
{
trace("Test.onUpdateTimer()");
trace("\t"+_stream.bytesLoaded+" of "+_stream.bytesTotal+" bytes loaded.");
trace("\t"+_stream.time+" of "+_metaData.duration+" played.");
trace("\t_stream.bufferLength...if (_stream.time >= _metaData.duration)
{
_updateTimer.removeEventListener... onUpdateTimer);
_updateTimer = null;
}
}is it just a case of rewriting that line or do I need to be calling new sprites or adding as children first?
anyone know?
- wwfc0
("larg... as Bitmap;
should be "largeimage"
- fusionpixel0
it seems like largeImage is expecting a bitmap not a NetStream, you need to write your logic to have largeImage accept either one or write an interface that will allow you to do that dynamically.
- wwfc0
so almost as simple as saying getnetstream (...) as video?
- wwfc0
...tried this
largeImage = largeImageLoader.getNetStream("l... as Video;largeImage = largeImageLoader.getVideo("large... as NetStream;
largeImage = largeImageLoader.getNetStream("l... as NetStream;
largeImage = largeImageLoader.getNetStream("l... as NetStream;
but none of them work largeimage is declared as Video in the vars but i don't know if that should be netstream too?
private var largeImageLoader:BulkLoader;
private var loadedArray:Array;
private var largeImage:Video;
private var largeImageItem:String;
private var _connection:NetConnection;
private var _stream:NetStream;
private var _video:Video;
private var _updateTimer:Timer;
private var _metaData:Object;
private var videoPackage:Video;??? not easy is it this as3 lark!
- maximillion_0
use http://pastebin.se and post yr code
- maximillion_0
and post the class BulkLoader
- bulkloader is the bulkloader straight from googlecodewwfc
- wwfc0
this is the netstream connection and setup
http://www.pastebin.se/196910it works and streams/loads/plays the flv
and this is block of script that I want to add it to
http://pastebin.se/196909
showlargeimage is the actual function - from line 140 onwardsand the current entire version - http://www.pastebin.se/196911
line 1791 onwards
- wwfc0
http://pastebin.se/196912
bulkloader
- wwfc0
and the version that works perfectly well with images but not vid.
no refs t the vid at all in there - but works peachy
- mrbee28280
1700+ lines = break it up into a class or 2
- wwfc0
lol! i know it is massive! - but is all applicable to the class - and i'm still trying to get my head round import and using classes - that is why i have ended creating that net stream within this class!
not good - but needs must
- maximillion_0
or more classes. thats quite bloated as is.
by reading the bulkloader class comments you need to provide the url (as a string) to the method getBitmap('you url here'). it will then return a bitmap object that has been loaded from that url. You dont need to typecast it as you did originally is "as Bitmap"
however you define largeImage as a video object:
private var largeImage:Video;if you want a bitmap then cast it as one:
private var largeImage:Bitmap
largeImage = largeImageLoader.getBitmap('your image url here');
I cant see a method that returns a video object in yr bulk uploader class so you might need to be more specific about what yr trying to do
- maximillion_0
wwfc - you might want to check out MVC frameworks for organising your code. http://puremvc.org/ is one that is popular
- wwfc0
...i have a sort image wall that the user can choose, click and zoom in on the clicked image - works fine with just images - but i need it to work with flvs/vids too.
but i couldn't get it to work with the xml - and had to rewrite and add bits to it to allow video - but this video now plays as an individual and not as the largeimage.
i also tried to call in this class StreamingVideoPlayer.as
http://www.pastebin.se/196917to stream and play the video - but couldn't work it out
so now i am trying to figure out which way to go - and - well could do with a little help really - try and clear the mists a bit.
ALL i want to do - is have the swf read the xml and if it is an image just call in the image and if it is video just bring in and play the video via that streaming player...
oh yeh - the moon on a stick too!!
- wwfc0
...nnnrgh~ - still not getting the drift at all!
okay - how do i tell the netstream object - to attach itself to the streamingvideoplayer that i have imported
import com.mediastuttgart.imageworld3d...
then
private var largeImageLoader:BulkLoader;
private var loadedArray:Array;
private var largeImage:Video;
private var largeImageItem:String;
private var _connection:NetConnection;
private var _stream:NetStream;
private var _video:Video;
private var _updateTimer:Timer;
private var _metaData:Object;
private var StreamingVideoPlayer;does it need to be a sprite/bitmap/video - or just as it is?
then apply it to this section of code
http://www.pastebin.se/196910what do i do to give it a skin via a class?
- wwfc0
...this is the streaming player class
http://www.pastebin.se/196917do i need to change that too?
- maximillion_0
dude, i havent got time to go through your code but read Colin Moocks pages to give you a better idea of how to organise yr code (assuming PUREMVC wasnt clear for you)
http://www.moock.org/lectures/gr…
- wwfc0
okay - will have a read up - i think i am at the part of the process where nothing sinks in - wood for the trees!
thanks for the pointers though ;-)
- maximillion_0
we've all been there. skip towards the bottom of that page and there are some analogies for classes/packages etc and how OOP works. this should make it clearer
- fusionpixel0
yeah