views:

72

answers:

2

I am working on the multifile uploader, and want to set the upload directory based on a selected questionID (which is the directory name) in my datagrid.

The code can be found here http://pastie.org/784185

Something like this:

I have set myQuestionID (the directory to upload to) so it is bindable (lines 136-137):

[Bindable] public var myQuestionID:int;

In my datagrid I use a change handler (line 539):

change="setQuestionID();"

We set the variable in the setQuestionID function (lines 400-407):

[Bindable (event="questionChange")]          
private function setQuestionID():void
{
     myQuestionID = questionsDG.selectedItem.QuestionID;
     dispatchEvent(new Event("questionChange"));
}

And then try to use it in my uploader script (lines 448-475):

// initUploader is called when account info loads
public function getSessionInfoResult(event:ResultEvent):void{           

        // Get jsessionid & questionid (final directory) for CF uploader
        myToken = roAccount.getSessionToken.lastResult;             
        // BUG: myQuestion is null in actionscript, but okay in form.

        var postVariables:URLVariables = new URLVariables();
        postVariables.jsessionid = myToken;
        postVariables.questionid = myQuestionID;            

        multiFileUpload = new MultiFileUpload(
                    filesDG,
                    browseBTN,
                    clearButton,
                    delButton,
                    upload_btn,
                    progressbar,
                    uploadDestination,
                    postVariables,
                    350000,
                    filesToFilter
                    );

         multiFileUpload.addEventListener(Event.COMPLETE,uploadsfinished);         
}

I can see in my MXML that the value binded (line 639):

<mx:Label text="{myDirectory}"/>

and it updates when I click a row in my datagrid. However, if I try to access this myQuestionID value inside any action script it will show as null (0). I know my uploader is working as I can hardcode myDirectory to a known directory and it will upload okay.

I'm really stumped.

A: 

Use dataGrid change event to set myDirectory everytime the selection has changed by user. this will update the value of myDirectory properly.

By making someID as Bindable would mostly solve your problem if you dont want to use change event on DG

scienty
A: 

The reason questionid = null is that getSessionInfoResult() is called by your init code before the bound value of myQuestionID is set.

So your file uploader (multiFileUpload) is already instantiated with myQuestionID = null.

You need to instantiate/pass the value into the multiFileUpload component after it is set.

johans
Yep, that was it - thank you Johan. I forget that in init() of an app that all values are set in stone if inside a function, and that you have to break free of that if you want your variables to be dynamic.
David Brannan