How to check if UPLOAD_COMPLETE_DATA event was not dispatched? - actionscript-3

Is there a way how to check if UPLOAD_COMPLETE_DATA event was not dispatched after COMPLETE in Flash?
I'm working on file uploader. It uploads file after file – after COMPLETE next file starts uploading – this is repeated for every file. On last file on COMPLETE if there is no next file allCompleteHandler is dispatched and if some errors occurs it shows that errors at once trough javascript to the user.
I handle that errors in javascript – it stores every error to variable in javascript and after all completed it shows that errors.
The problem is:
I can't store error from the last file (error from server that I get through UPLOAD_COMPLETE_DATA) because this is dispatched after COMPLETE (after allCompleteHandler).
I need to solve this because I don't wont to show javascript alert box for every invalid file (if there are 100 files for example).
var parameters:Object = LoaderInfo(this.root.loaderInfo).parameters,
fileFilter:Array,
browseFilter:Array = [],
files:FileReferenceList = new FileReferenceList(),
selectedFiles:Array = [],
file:FileReference = new FileReference(),
url:URLRequest = new URLRequest(parameters.phpScript),
uploadFolder,
postMaxSize:Number,
uploadMaxFilesize:Number,
maxInputTime:int,
speedTimer:Timer = new Timer(1000),
uploadTimer:Timer = new Timer(60000, 1),
count:int = 0,
totalBytes:Number = 0,
processedBytes:Number = 0,
currentBytes:Number = 0,
currentBytes2:Number = 0,
lastBytes:Number = 0,
uploadSpeed:Number = 0,
inProgress:Boolean = false;
// Browse filter setup
fileFilter = ExternalInterface.call(parameters.fileManager + ".getFileFilter");
if (fileFilter) {
for (var i:int = 0; i < fileFilter.length; i++) {
browseFilter.push(new FileFilter(fileFilter[i][0], fileFilter[i][1]));
}
}
function clickHandler(event:MouseEvent):void {
if (!inProgress) {
uploadFolder = ExternalInterface.call(parameters.fileManager + ".getCurrentFolder");
if (uploadFolder != undefined) {
files.browse(browseFilter);
}
}
}
stage.addEventListener(MouseEvent.CLICK, clickHandler);
function selectHandler(event:Event):void {
var variables:URLVariables = new URLVariables();
variables.folder = uploadFolder;
url.data = variables;
url.method = URLRequestMethod.POST;
selectedFiles = files.fileList;
postMaxSize = ExternalInterface.call(parameters.fileManager + ".getPostMaxSize");
postMaxSize = postMaxSize ? postMaxSize : 50 * 1024 * 1024;
uploadMaxFilesize = ExternalInterface.call(parameters.fileManager + ".getUploadMaxFilesize");
uploadMaxFilesize = uploadMaxFilesize ? uploadMaxFilesize : 50 * 1024 * 1024;
maxInputTime = ExternalInterface.call(parameters.fileManager + ".getMaxInputTime");
maxInputTime = maxInputTime ? maxInputTime : 60;
// Get total size of selected files
for (var i:int = 0; i < selectedFiles.length; i++) {
totalBytes += selectedFiles[i].size;
}
ExternalInterface.call(parameters.fileManager + ".selectHandler", {
selectedFiles : selectedFiles,
totalBytes : totalBytes
});
// Start upload process
inProgress = true;
speedTimer.start();
upload();
}
files.addEventListener(Event.SELECT, selectHandler);
function upload():void {
uploadTimer.reset();
currentBytes2 = 0;
if (count) {
processedBytes += file.size;
if (currentBytes < processedBytes) {
currentBytes = processedBytes;
}
}
if (selectedFiles.length) {
file = FileReference(selectedFiles.shift());
count++;
ExternalInterface.call(parameters.fileManager + ".beforeUploadHandler", {
file : file,
currentBytes : currentBytes
});
if (file.size <= postMaxSize) {
if (file.size <= uploadMaxFilesize) {
file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
file.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler);
file.addEventListener(Event.OPEN, openHandler);
file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
file.addEventListener(Event.COMPLETE, completeHandler);
file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, uploadCompleteDataHandler);
file.upload(url);
} else {
ExternalInterface.call(parameters.fileManager + ".uploadMaxFilesizeHandler", file);
upload();
}
} else {
ExternalInterface.call(parameters.fileManager + ".postMaxSizeHandler", file);
upload();
}
} else {
ExternalInterface.call(parameters.fileManager + ".allCompleteHandler", {
currentBytes : currentBytes
});
speedTimer.stop();
count = 0;
totalBytes = 0;
processedBytes = 0;
currentBytes = 0;
lastBytes = 0;
uploadSpeed = 0;
inProgress = false;
}
}
function securityErrorHandler(event:SecurityErrorEvent):void {
ExternalInterface.call(parameters.fileManager + ".securityErrorHandler", event);
}
function httpStatusHandler(event:HTTPStatusEvent):void {
ExternalInterface.call(parameters.fileManager + ".httpStatusHandler", event);
selectedFiles = [];
}
function openHandler(event:Event):void {
ExternalInterface.call(parameters.fileManager + ".openHandler", event);
uploadTimer.delay = maxInputTime * 1000;
uploadTimer.start();
}
function ioErrorHandler(event:IOErrorEvent):void {
ExternalInterface.call(parameters.fileManager + ".ioErrorHandler", event);
upload();
}
function progressHandler(event:ProgressEvent):void {
currentBytes += event.bytesLoaded - currentBytes2;
currentBytes2 = event.bytesLoaded;
ExternalInterface.call(parameters.fileManager + ".progressHandler", {
current : event,
currentBytes : currentBytes
});
}
function completeHandler(event:Event):void {
ExternalInterface.call(parameters.fileManager + ".completeHandler", event);
upload();
}
function uploadCompleteDataHandler(event:DataEvent):void {
ExternalInterface.call(parameters.fileManager + ".uploadCompleteDataHandler", "(" + event.data + ")");
}
function updateUploadSpeed(event:TimerEvent):void {
if (currentBytes > lastBytes) {
uploadSpeed = currentBytes - lastBytes;
ExternalInterface.call(parameters.fileManager + ".uploadSpeedHandler", uploadSpeed);
lastBytes = currentBytes;
}
}
speedTimer.addEventListener(TimerEvent.TIMER, updateUploadSpeed);
function maxInputTimeHandler(event:TimerEvent):void {
ExternalInterface.call(parameters.fileManager + ".maxInputTimeHandler", file);
}
uploadTimer.addEventListener(TimerEvent.TIMER, maxInputTimeHandler);
function cancelUpload():void {
file.cancel();
selectedFiles = [];
upload();
}
ExternalInterface.addCallback("cancelUpload", cancelUpload);
I can do this by setting up my PHP script to always return data and check this data and start next file upload with UPLOAD_COMPLETE_DATA, but I don't like this (it can be slow maybe I think)...
It is simple question but maybe hard to explain why I need that. Thank you for your help!

okay, what about http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/FileReference.html#event:progress
and sample
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/net/FileReference.html#includeExamplesSummary
http://blog.flexexamples.com/2007/10/30/using-for-the-filereference-classs-uploadcompletedata-event-to-capture-data-from-a-server-side-script/
http://bcdef.org/2006/12/09/new-event-for-as3-filereference-uploadcompletedata/
From the docs:
uploadCompleteData:
Dispatched after data is received from the server after a successful upload. This event is not dispatched if data is not returned from the server.
complete:
Dispatched when download is complete or when upload generates an HTTP status code of 200. For file download, this event is dispatched when Flash Player or Adobe AIR finishes downloading the entire file to disk. For file upload, this event is dispatched after the Flash Player or Adobe AIR receives an HTTP status code of 200 from the server receiving the transmission.
So, if you're uploading a file and not expecting any kind of response from the server you can just use complete. However, if you're expecting the server to return data to you in the upload's response then you need to wait for uploadCompleteData.

Related

code is not working for rewinding a dynamically added video

I have loaded a flv video dynamically from as3 library. Now I want to rewind it, but code is not working. Showing:
Scene 1, Layer 'Layer 1', Frame 1, Line 64 1119: Access of possibly
undefined property playheadTime through a reference with static type
flash.media:Video..
Here is my code. I could not find the problem. Any help would be great.
stage.displayState = StageDisplayState.FULL_SCREEN;
import flash.media.Video;
import fl.video.FLVPlayback;
var connection:NetConnection = new NetConnection();
var stream:NetStream;
var Speed:Number;
var SeekPoint:Number;
var Rewind:Boolean ;
var Forward:Boolean ;
var video:Video = new Video(1130,510);
var metaObj:Object = new Object();
function onMetaData(data:Object):void
{
}
connection.connect(null);
stream = new NetStream(connection);
stream.client = metaObj;
metaObj.onMetaData = onMetaData;
video.attachNetStream(stream);
addChild(video);
stream.play("Sequence 01_1.flv");
video.x = 0;
video.y = 0;
rw.addEventListener(MouseEvent.MOUSE_DOWN, rw_CLICK);
function rw_CLICK(event:MouseEvent):void
{
trace("StartForward Called");
Speed = Speed +10;
trace("SeekSpeed: " + Speed);
SeekPoint = video.playheadTime;
trace("Initial PlayHead Time: " + SeekPoint);
video.stop();
Rewind = false
Forward= true;
//video.addEventListener(Event.FRAME_CONSTRUCTED,OnConstructFrame);
}
function OnConstructFrame(event:Event):void
{
if(Forward)
{
if(video.playheadTime >= SeekPoint)
{
trace("Before Seek Cal.: " + SeekPoint);
SeekPoint = SeekPoint + Speed;
trace("After Seek Cal.: " + SeekPoint);
video.seek(SeekPoint);
/* if(SeekPoint > ftime)
{
Forward=false;
// video.removeEventListener(Event.FRAME_CONSTRUCTED,OnExitFrame);
}*/
}
}
}
The VideoClass don't have a property playheadTime.
You have to get the time-property of the NetStream-Object.
Further there is no seek-method. Both are only available in the FLVPlayback-Component.
You should use play(name, time)
If you are working with Netstreamand `Video' you can use this:
...
if(stream.time >= SeekPoint) //in seconds
{
trace("Before Seek Cal.: " + SeekPoint);
SeekPoint = SeekPoint + Speed;
trace("After Seek Cal.: " + SeekPoint);
stream.play("Sequence 01_1.flv", SeekPoint);
/* if(SeekPoint > ftime)
{
Forward=false;
// video.removeEventListener(Event.FRAME_CONSTRUCTED,OnExitFrame);
}*/
}
...
Greetings André

AS3,AIR,Socket. How to check the progress of a writeObject() transfer?

I'm dealing with AIR and Sockets, using a Server app and another as Client.
Server sends an object to Client:
clientSocket.writeObject(myObject);
Client has a listener, like this:
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketData);
How can I know the size of the incoming object? I need to monitoring this process, cause when the transfer is complete I need to do another processes.
I tried this, but doesn't work :
var total:int = 0;
private function socketData(e:ProgressEvent) :void {
if (total == 0) {
total = socket.readInt();
}
if (socket.bytesAvailable >= total) {
trace('COMPLETE');
total = 0;
} else {
trace('progress:' + socket.bytesAvailable + ' | total: ' + total);
}
}
This post does not work in my specific case: AS3 / AIR readObject() from socket - How do you check all data has been received?
I resolve it, with a hack:
SERVER: Send an object:
clientSocket.writeObject(image);// var image:Bitmap
clientSocket.flush();
CLIENT:
A. Have a listener to receive socket data:
socket.addEventListener(ProgressEvent.SOCKET_DATA, socketData);
B. Receive the bytes. When all the bytes are available, then read the object:
private var prevBytes:int = -1;
private var currentBytes:int = 0;
private function onEnterFrame(e:Event):void {
if (currentBytes == prevBytes) {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
currentBytes = 0;
prevBytes = -1;
var obj:* = socket.readObject();
} else {
prevBytes = currentBytes;
}
trace('Current : ' + currentBytes + ' | Prev : ' + prevBytes);
}
private function socketData(e:ProgressEvent):void {
trace('on socketData : ' + currentBytes);
if (currentBytes == 0) {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
currentBytes = socket.bytesAvailable;
}

Timer related error in flash, TypeError #1009

I used a timer in my flash application, and I have this particular error below:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at FlashGame_fla::MainTimeline/toTimeCode()
at FlashGame_fla::MainTimeline/timerTickHandler()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
Below is my code for this particular flash game application. It's a game where the player collects as many items as possible within a specific time:
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.geom.Rectangle;
menuButton.addEventListener(MouseEvent.CLICK, evilToMenu);
rulesButton.addEventListener(MouseEvent.CLICK, toggleRule);
gameRules.addEventListener(MouseEvent.CLICK, toggleRule);
gameRules.visible = false;
gameRules.buttonMode = true;
evilGameOverMC.visible = false;
evilWinLose.visible = false;
playAgainBtn.visible = false;
toMenuBtn.visible = false;
var pLives:int = 3;
var pEvilScore:int = 0;
var pItems:int = 10;
var daveMC:MovieClip;
var cGameObjs:Array = new Array();
var timer:Timer = new Timer(100, 300);
timer.start();
timer.addEventListener(TimerEvent.TIMER, timerTickHandler);
var timerCount:int = 15000;
//var cPlayerData:Object;
//var cSavedGameData:SharedObject;
addCharacter();
addBots();
addItems();
scoreDisplay.text = "" + pEvilScore;
livesDisplay.text = pLives + " lives";
function evilToMenu(Event:MouseEvent):void
{
removeLeftovers();
removeChild(daveMC);
timer.stop();
gotoAndStop("menu");
}
function timerTickHandler(Event:TimerEvent):void
{
timerCount -= 100;
toTimeCode(timerCount);
if (timerCount <= 0)
{
gameOver(false);
}
}
function toTimeCode(milliseconds:int): void
{
//creating a date object using the elapsed milliseconds
var time:Date = new Date(milliseconds);
//define minutes/seconds/mseconds
var minutes:String = String(time.minutes);
var seconds:String = String(time.seconds);
var miliseconds:String = String(Math.round(time.milliseconds)/100);
//add zero if neccecary, for example: 2:3.5 becomes 02:03.5
minutes = (minutes.length != 2) ? '0'+minutes : minutes;
seconds = (seconds.length != 2) ? '0'+seconds : seconds;
//display elapsed time on in a textfield on stage
timerDisplay.text = minutes + ":" + seconds;
}
function addCharacter():void
{
trace("Adding the character, Dave")
//set the initial values
var myBorder:Rectangle = new Rectangle(355,145,395,285);
var myXY:Array = [355,430];
var myChar:int = Math.ceil(Math.random() * 3);
var myKeys:Array = [37,39,38,40];
var myDistance:int = 7;
// create and add a new player object to the stage
daveMC = new Character(myBorder,myXY,myKeys,myChar,myDistance);
addChild(daveMC);
}
function addBots():void
{
trace("Adding the bots..");
// set the initial values (adapt to suit your game)
var myBorder:Rectangle = new Rectangle(355,145,395,285);
var myMaxBots:int = 5;// simulation
// add bots one at a time via a loop
for (var i:int = 0; i < myMaxBots; i++)
{
// create a new bot object and name it
var thisBot:Bot = new Bot(myBorder, daveMC);
thisBot.name = "bot" + i;
cGameObjs.push(thisBot);
// add it to the stage
addChild(thisBot);
}
}
function addItems():void
{
trace("Adding the items..");
//set the initial values
for (var i:int = 0; i < 10; i++)
{
// create a new bot object and name it
var thisItem:Item = new Item(daveMC);
thisItem.name = "item" + i;
cGameObjs.push(thisItem);
// add it to the stage
addChild(thisItem);
}
}
function updateLives(myBot:MovieClip):void
{
// update the player's LIVES and score
pLives--;
pEvilScore -= 30;
var myIndex:int = cGameObjs.indexOf(myBot);
cGameObjs.splice(myIndex,1);
// check for a LOST GAME
if (pLives > 0)
{
updateScores();
}
else
{
gameOver(false);
}
}
function updateItems(myItem:MovieClip):void
{
// update the player's LIVES and score
pItems--;
pEvilScore += 20;
var myIndex:int = cGameObjs.indexOf(myItem);
cGameObjs.splice(myIndex,1);
// check for a LOST GAME
if (pItems > 0)
{
updateScores();
}
else
{
gameOver(true);
}
}
function gameOver(myFlag:Boolean):void
{
updateScores();
if (myFlag)
{
// player wins
msgDisplay.text = "YAY! PAPPLE FOR \nEVERYBODY!";
removeLeftovers();
evilWinLose.text = "Weee!! We've got papples for Gru! \nYour Score: " + pEvilScore;
}
else
{
// player loses
msgDisplay.text = "OH NO! NOT \nENOUGH PAPPLES";
removeLeftovers();
evilWinLose.text = "Boo!! Not enough papples for Gru! \nYour Score: " + pEvilScore;
}
timerDisplay.text = "";
removeChild(daveMC);
evilGameOverMC.visible = true;
evilWinLose.visible = true;
toMenuBtn.visible = true;
playAgainBtn.visible = true;
toMenuBtn.addEventListener(MouseEvent.CLICK, Click_backtoMain);
playAgainBtn.addEventListener(MouseEvent.CLICK, backToEvil);
}
function updateScores():void
{
scoreDisplay.text = "" + pEvilScore;
livesDisplay.text = pLives + " lives";
msgDisplay.text = pItems + " papples more to \ncollect..";
}
function removeLeftovers():void
{
// check each BOT/ITEM in array
for each (var myObj in cGameObjs)
{
myObj.hasHitMe();
myObj = null;
}
}
function backToEvil(event:MouseEvent):void
{
pEvilScore = 0;
pLives = 3;
pItems = 3;
gotoAndStop("menu");
gotoAndStop("evil");
}
Anyone can help me out with this? Thank you alot! :)
Replace your toTimeCode function code by :
function toTimeCode(milliseconds:int): void
{
trace(1);
//creating a date object using the elapsed milliseconds
var time:Date = new Date(milliseconds);
trace(2);
//define minutes/seconds/mseconds
var minutes:String = String(time.minutes);
trace(3);
var seconds:String = String(time.seconds);
trace(4);
var miliseconds:String = String(Math.round(time.milliseconds)/100);
trace(5);
//add zero if neccecary, for example: 2:3.5 becomes 02:03.5
minutes = (minutes.length != 2) ? '0'+minutes : minutes;
trace(6);
seconds = (seconds.length != 2) ? '0'+seconds : seconds;
trace(7);
//display elapsed time on in a textfield on stage
timerDisplay.text = minutes + ":" + seconds;
trace(8);
}
Please, change the timerDisplay line to this one... The problem will be in the toTimeCode method. The error say that you are trying to call a method from a var wich is not (yet) an object...
if(null != timerDisplay)
timerDisplay.text = minutes + ":" + seconds;
You have to find an object wich is null! Add this :
function toTimeCode(milliseconds:int): void
{
//creating a date object using the elapsed milliseconds
var time:Date = new Date(milliseconds);
trace("Time: " + time);

AS3 creating dynamic Loader Names in a loop

EDITED for clarity: I want to load all kinds of images from an external url in a for loop.
I want to call them in a loop and when it's over I start the loop again. however I don't want to call them again with an "http request" rather I would like to loop through the loaded images over and over again.
Is it possible to create a dynamic Loader name in a loop?
Here is the code example:
var Count = 0;
// Loop Begins
var Count:Loader = new Loader();
Count.load(new URLRequest("myurl");
addChild(Count);
Count++;
// End Loop
Another example would be to have a NAME and just add the number on the end. But how
var Count = 0;
// Loop Begins
var MyName+Count:Loader = new Loader();
MyName+Count.load(new URLRequest("myurl");
addChild(MyName+Count);
Count++;
// End Loop
IN SHORT:
I want to load a bunch of images into an Array and loop through the loaded images by calling them later.
Thanks so much!
CASE1 code is how to load images in Sequence.
CASE2 code is how to load images in Synchronized.
First, the URL you want to import all images must be named sequentially.
for example Must be in the following format:
www.myURL.com/img0.jpg
www.myURL.com/img1.jpg
www.myURL.com/img2.jpg
www.myURL.com/img3.jpg
www.myURL.com/img4.jpg
www.myURL.com/img5.jpg
.
.
.
Try the code below, just a test.
CASE1
var imgLoader:Loader;
var imgRequest:URLRequest;
var count:int = -1;
const TOTAL_COUNT:int = 10;
var imgBox:Array = [];
var isCounting:Boolean;
function loadImage():void
{
count ++;
isCounting = true;
imgLoader = new Loader();
imgRequest = new URLRequest();
imgRequest.url = "www.myURL.com/img" + count +".jpg";
imgLoader.load(imgRequest);
imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, unloadedImg);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedImg);
if(count == TOTAL_COUNT)
{
isCounting = false;
count = -1;
}
}
function onLoadedImg(e:Event):void
{
imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadedImg);
var bmp:Bitmap = e.currentTarget.content;
bmp.x = Math.random() * width;
bmp.y = Math.random() * height;
bmp.width = 100;
bmp.height = 100;
this.addChild(bmp);
imgBox.push(bmp);
if( isCounting == false)
{
return;
}
loadImage();
}
function unloadedImg(e:IOErrorEvent):void
{
imgLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, unloadedImg);
trace("load Failed:" + e);
}
loadImage();
CASE2
var imgLoader:Loader;
var imgRequest:URLRequest;
const TOTAL_COUNT:int = 10;
var imgBox:Array = [];
function loadImage2():void
{
for(var i:int = 0; i<TOTAL_COUNT; i++)
{
imgLoader = new Loader();
imgRequest = new URLRequest();
imgRequest.url = "www.myURL.com/img" + i +".jpg";
imgLoader.load(imgRequest);
imgLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, unloadedImg);
imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedImg);
}
}
function onLoadedImg(e:Event):void
{
imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onLoadedImg);
var bmp:Bitmap = e.currentTarget.content;
bmp.x = Math.random() * width;
bmp.y = Math.random() * height;
bmp.width = 100;
bmp.height = 100;
this.addChild(bmp);
imgBox.push(bmp);
}
function unloadedImg(e:IOErrorEvent):void
{
imgLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, unloadedImg);
trace("load Failed:" + e);
}
loadImage2();
If you want access loaded Image. refer a following code. If you do not put them in an array can not be accessed in the future.
for(var int:i=0; i<TOTAL_COUNT; i++)
{
var bitmap:Bitmap = imgBox[i] as Bitmap;
trace("index: " + i + "x: " + bitmap.x + "y: " + bitmap.y, "width: " + bitmap.width + "height: " + bitmap.height);
}
Now that we're on the same page:
var imgArray:Array = new Array;
var totalImages:int = 42;
var totalLoaded:int = 0;
var loaded:Boolean = false;
function loadImages():void{
for(var count:int = 0; count < totalImages; count++){
var image:Loader = new Loader();
image.load(new URLRequest("image" + i + ".jpg");
image.addEventListener(Event.COMPLETE, loaded);
imgArray.push(image);
}
}
function loaded(e:Event):void{
totalLoaded++;
if (totalLoaded == totalImages){
loaded = true;
}
}
function displayImages():void{
if (loaded){
for(var i:int = 0; i < imgArray.length(); i++){
addChild(imgArray[i]);
}
}
}

Flash CS5 AS3 Can not get Flashvars

I am new to fairly new to AS3 and I have found myself needing to extend a fla. that was written by a 3rd party.
The goal is to access flashvars but for the life of me can not get it to work...been at it for days learning..
the fla I am working with is code on timeline with 2 frames. the movieclip runs to frame 2 ans stops.
On frame 2 is where I require the use of the flashvar.
I have built a simple example that will populate a textbox on frame two that works fine.
frame 1
var my_var:String = new String();
my_var = root.loaderInfo.parameters.uploadId;
frame 2
my_txt.text = my_var;
stop();
However when I use the same approach on my 3rd party fla I get NULL output. I am not using any TLF text either (I think).
I don't understand why it works in one case but not the other. I am thinking it might have to do with conflict with the surrounding code but I don't know enough about AS to track it down. Any help on this would be greatly appreciated.
frame 1
import net.bizmodules.uvg.loading;
stop();
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.showDefaultContextMenu = false;
stage.quality = StageQuality.BEST;
function RandomValue()
{
var d = new Date();
return String(d.getDate()) + String(d.getHours()) + String(d.getMinutes()) + String(d.getSeconds());
}
var my_var:String;
my_var = root.loaderInfo.parameters.uploadId;
var userId;
var albums:Object;
var resource:Object;
var strUploadPage:String;
if (root.loaderInfo.parameters.uploadPage != undefined)
strUploadPage = root.loaderInfo.parameters.uploadPage;
else
strUploadPage = "http://localhost/dnn450/desktopmodules/ultramediagallery/flashuploadpage.aspx?PortalId=0&ModuleId=455";
if (strUploadPage.indexOf("?") > 0)
strUploadPage += "&";
else
strUploadPage += "?";
strUploadPage += "action=loadAlbums&seed=" + RandomValue();
trace(strUploadPage);
var myLoading:MovieClip = new loading();
myLoading.x = (stage.stageWidth - myLoading.width) / 2;
myLoading.y = (stage.stageHeight - myLoading.height) / 2;
addChild(myLoading);
var myRequest:URLRequest = new URLRequest(strUploadPage);
var myLoader:URLLoader = new URLLoader(myRequest);
myLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(evtObj:Event)
{
myLoader.removeEventListener(Event.COMPLETE, xmlLoaded);
try
{
var xDoc:XMLDocument = new XMLDocument();
xDoc.ignoreWhite = true;
var xml:XML = XML(myLoader.data);
xDoc.parseXML(xml.toXMLString());
userId=xDoc.firstChild.attributes.userId;
if (userId < 0)
{
removeChild(myLoading);
txtError.text = "Please ensure you are logged in";
return;
}
if(xDoc.firstChild.childNodes.length > 0)
{
albums = xDoc.firstChild.childNodes[0].childNodes;
resource = xDoc.firstChild.childNodes[1].attributes;
}
else
{
removeChild(myLoading);
txtError.text = xDoc.firstChild.attributes.error;
return;
}
play();
}
catch(e:Error)
{
removeChild(myLoading);
txtError.text = e + "\n\nPlease check your Event Viewer to find out detailed error message and contact service#bizmodules.net";
}
}
frame 2
import net.bizmodules.upg.Alert;
stop();
removeChild(myLoading);
initialize();
function initialize()
{
Alert.init(stage);
upload.addVar("userId",userId);
lstAlbums.dropdown.rowHeight = 24;
loadAlbums(0, albums);
var my_so:SharedObject = SharedObject.getLocal("UPGUpload");
var lastAlbum = my_so.data.lastAlbum * 1;
var foundLastAlbum = false;
if (lastAlbum > 0)
{
for (var i:int = 0; i< lstAlbums.length; i++)
{
if (lstAlbums.getItemAt(i).data == lastAlbum)
{
trace("find previous album");
foundLastAlbum = true;
lstAlbums.selectedIndex = i;
break;
}
}
}
if (!foundLastAlbum)
{
lstAlbums.selectedIndex = lstAlbums.length - 1;
}
albums_change(null);
lstAlbums.addEventListener("change", albums_change);
lstAlbums.setStyle("backgroundColor", 0x504C4B);
lstAlbums.dropdown.setStyle("backgroundColor", 0x504C4B);
lstAlbums.setStyle("themeColor", 0x1F90AE);
lstAlbums.setStyle("color", 0xC4C0BF);
lstAlbums.setStyle("textSelectedColor", 0xC4C0BF);
lstAlbums.setStyle("textRollOverColor", 0xC4C0BF);
lstAlbums.setStyle("alternatingRowColors", [0x504C4B, 0x504C4B]);
lstAlbums.setStyle("borderStyle", 'none');
}
my_txt.text = "hello" + " " + my_var;
function loadAlbums(level:int, xml:Object)
{
var prefix = " ".substring(0, level * 4);;
for (var i:int = 0;i<xml.length;i++)
{
var itemValue = xml[i].attributes.itemid;
if (xml[i].childNodes.length > 0)
itemValue *= -1;
lstAlbums.addItem({data: itemValue, label: prefix + xml[i].attributes.name});
if (xml[i].childNodes.length > 0)
{
loadAlbums(level + 1, xml[i].childNodes);
}
}
}
function albums_change(e)
{
var albumId = lstAlbums.getItemAt(lstAlbums.selectedIndex).data;
upload.set_albumId(albumId);
if (albumId > 0)
{
var my_so:SharedObject = SharedObject.getLocal("UPGUpload");
my_so.data.lastAlbum = albumId;
}
else
{
Alert.show("The album you choosed is invalid", null, 0xEAEAEA, 0x000000);
}
}
private var flashVarObj:Object = new Object;
flashVarObj=LoaderInfo(this.loaderInfo).parameters;
var my_var:String = new String();
my_var = flashVarObj.uploadIdd;