PDA

View Full Version : DateChooser [object Object]


fsumanning
02-09-2005, 07:51 PM
I'm using ActionScript 2.0 and the DateChooser. I have a button that when clicked, creates a DateChooser and applies some formatting. I then create a listener object in order to capture the change event. When a new date is selected I have it filling in a Input text box using a call to _root.textboxname.text. This all works as planned.

Here is the problem. When a new date is selected, the text box fills in and then a javascript type box pops up and says [object Object] . I don't know why this is happening or how to fix it. I have noticed that the problem occurs only if the listener is added to the DateChooser.

Here is the code:

on (release) {
import mx.controls.DateChooser;
var myDateChooser:DateChooser = createClassObject(DateChooser,"dateChooserComp",10 /* init object? ,{label:"Test Button"}*/);
myDateChooser._x = 180;
myDateChooser._y = 120;
myDateChooser.scaleX = 210;
myDateChooser.scaleY = 210;
myDateChooser.disabledDays = [0,6];
myDateChooser.setStyle("fontSize", "15");
myDateChooser.selectableRange = {rangeStart:new Date()};

var listenerObj:Object = new Object();
listenerObj.change = function(eventObj){
trace("Detected and Date change...");

var month = eventObj.target.selectedDate.getMonth()+1;
var day = eventObj.target.selectedDate.getDate();
var year = eventObj.target.selectedDate.getFullYear();

if(month < 10) {month = "0" + month;}
if(day < 10) {month = "0" + day;}

_root.buildInspDate_txt.text = month + "/" + day + "/" + year;
//eventObj.target.destroyObject("dateChooserComp");
}
myDateChooser.addEventListener("change", listenerObj);
}

As you can see I am not supplying an initialization object. Also, I want to remove DateChooser once a date is selected. That removal code has not been implemented as of yet.

Thanks in advance for any help provided.

scot
02-09-2005, 08:09 PM
where are you getting [object object] in a html Page or in the Output Panel ........

[object object ] means your referencing a object ...

example....... of [object object]
tmpAr = new Array()
tmpAr.push({id:"0",name:"something"})
trace(tmpAr) will give you [object object]


I just tested your code and it worked fine for me ... with no [object object]

fsumanning
02-09-2005, 08:15 PM
I'm getting it when I run in IE 6.

fsumanning
02-09-2005, 08:19 PM
I just included the DateChooser just off the stage and gave it an instance name. I then used the following code to put it on the stage, then add the listener. When a date is selected the text box is filled in and the instance moves off the stage.

on(release){
testDateChooser.scaleX = 210;
testDateChooser.scaleY = 210;
testDateChooser.disabledDays = [0,6];
testDateChooser.setStyle("fontSize", "15");
testDateChooser.selectableRange = {rangeStart:new Date()};
testDateChooser._x = 180;
testDateChooser._y = 120;

var listenerObj:Object = new Object();
listenerObj.change = function(eventObj){
trace("Detected and Date change...");

var month = eventObj.target.selectedDate.getMonth()+1;
var day = eventObj.target.selectedDate.getDate();
var year = eventObj.target.selectedDate.getFullYear();

if(month < 10) {month = "0" + month;}
if(day < 10) {month = "0" + day;}

_root.buildInspDate_txt.text = month + "/" + day + "/" + year;
eventObj.target._x = 1105;
eventObj.target._y = 166;
}
testDateChooser.addEventListener("change", listenerObj);
}

It fills the text box and moves off the stage but I still get the alert box in IE that says [object Object].

scot
02-09-2005, 08:27 PM
try this put all your code thats on the button in a function on your main time line ... and then have your button call the function .. and see what happens....... if that no helps can you post a link to a example of the problem.....

fsumanning
02-09-2005, 09:00 PM
So here is the latest attemp. I added to following code on the first frame of one of my layers.


function selectDate(textBox){
testDateChooser.setStyle("fontSize", "15");
testDateChooser.selectableRange = {rangeStart:new Date()};
testDateChooser.disabledDays = [0,6];
testDateChooser.scaleX = 210;
testDateChooser.scaleY = 210;
testDateChooser._x = 180;
testDateChooser._y = 120;

var listenerObj:Object = new Object();
listenerObj.change = function(eventObj){
trace("Detected and Date change...");

var month = eventObj.target.selectedDate.getMonth()+1;
var day = eventObj.target.selectedDate.getDate();
var year = eventObj.target.selectedDate.getFullYear();

if(month < 10) {month = "0" + month;}
if(day < 10) {month = "0" + day;}

textBox.text = month + "/" + day + "/" + year;

eventObj.target._x = 1105;
eventObj.target._y = 166;
}
testDateChooser.addEventListener("change", listenerObj);
}


Note there is a parameter "textBox" that makes this more general use. I then changed the button code to be the following:


on(release){
selectDate(buildInspDate_txt);
}


[object Object] PROBLEM STILL EXISTS!

I love Flash!

fsumanning
02-09-2005, 09:05 PM
I also decided to try something I saw in an example from the book FlashMX 2004 Actionscript published by Macromedia. I tried the following:


function selectDate(textBox){
testDateChooser.setStyle("fontSize", "15");
testDateChooser.selectableRange = {rangeStart:new Date()};
testDateChooser.disabledDays = [0,6];
testDateChooser.scaleX = 210;
testDateChooser.scaleY = 210;
testDateChooser._x = 180;
testDateChooser._y = 120;

//var listenerObj:Object = new Object();
//listenerObj.change =
function placeDate(eventObj:Object){
trace("Detected and Date change...");

var month = eventObj.target.selectedDate.getMonth()+1;
var day = eventObj.target.selectedDate.getDate();
var year = eventObj.target.selectedDate.getFullYear();

if(month < 10) {month = "0" + month;}
if(day < 10) {month = "0" + day;}

textBox.text = month + "/" + day + "/" + year;

eventObj.target._x = 1105;
eventObj.target._y = 166;
}
testDateChooser.addEventListener("change", placeDate);
}


I basically removed the creation of the listenerObj and passed the function placeDate() to the addEventListener() call. The button code remained the same as before.

Unfortunately, I got the same results!

fsumanning
02-09-2005, 09:32 PM
I checked these in Mozilla as well and got the same results.

fsumanning
02-09-2005, 09:47 PM
I decided to add some calls to an existing function that does a javascript alert() call. The function that does this is the following:


_global.Object.prototype.alert = function (message) {
getURL("javascript:alert('"+message+"')");
}


I changed the listener so that it has these calls after the date is formatted:


var formattedDate:String = month + "/" + day + "/" + year;
textBox.text = formattedDate;
alert(formattedDate);


Interestingly, the [object Object] message does not appear with the alert is used. As soon as I comment out the alert call, the object javascript error reappears. This by no means fixes my problem and I'm guessing this is just some stupid Javascript trick that is clearing out the other message.

scot
02-09-2005, 10:00 PM
flash I know .... java .........whatever....just a bit.... dont use it.... but this AS pops up a date and show it in a txt box ......

// ............................
someTextFormat = new TextFormat();
someTextFormat.color = 0x000000;
someTextFormat.bullet = 0;
someTextFormat.underline = 0;
someTextFormat.font = "hooge 05_63";
someTextFormat.size = 16;
// proto to draw a box ........
MovieClip.prototype.drawBox = function(x, y, w, h, lineWidth, lineColor, bgColor, bgAlpha) {
this.beginFill(bgColor, bgAlpha);
this.lineStyle(lineWidth, lineColor, 100);
this.moveTo(x, y);
this.lineTo(x+w, y);
this.lineTo(x+w, y+h);
this.lineTo(x, y+h);
this.endFill();
};
//...........draw box with a text field
MovieClip.prototype.drawTextBox = function(n, w, h, x, y, l_color, b_color) {
this._x = x;
this._y = y;
this.createEmptyMovieClip("bck", this.getNextHighestDepth());
this.bck.drawBox(0, 0, w, h, 1, l_color, b_color, 100);
this.createTextField("dtf", this.getNextHighestDepth(), 5, 4, w, 20);
this.dtf.multiline = true;
this.dtf.selectable = 0;
this.dtf.wordWrap = true;
this.dtf.border = false;
this.dtf.text = n;
this.dtf.setTextFormat(someTextFormat);
};
// make a button w/ ro*2
MovieClip.prototype.makeButton = function(n, w) {
this.drawTextBox(n, 140, 30, 0, 0, 0x000000, 0xffffff);
this.onRollOver = function() {
this._x = this._x+2;
this._y = this._y+2;
};
this.onRollOut = function() {
this._x = this._x-2;
this._y = this._y-2;
};
this.onPress = function() {
x = eval(w);
x();
};
};
// select a date
function selectDate() {
import mx.controls.DateChooser;
this.createEmptyMovieClip("cal", this.getNextHighestDepth());
cal.createClassObject(mx.controls.DateChooser, "testDateChooser", this.cal.getNextHighestDepth());
cal.testDateChooser.setStyle("fontSize", "15");
cal.testDateChooser.selectableRange = {rangeStart:new Date()};
cal.testDateChooser.disabledDays = [0, 6];
cal.testDateChooser.scaleX = 210;
cal.testDateChooser.scaleY = 210;
cal._x = 180;
cal._y = 120;
var listenerObj:Object = new Object();
listenerObj.change = function(eventObj) {
trace("Detected and Date change...");
var month = eventObj.target.selectedDate.getMonth()+1;
var day = eventObj.target.selectedDate.getDate();
var year = eventObj.target.selectedDate.getFullYear();
if (month<10) {
month = "0"+month;
}
if (day<10) {
month = "0"+day;
}
output.dtf.text ="OUTPUT : " + month+"/"+day+"/"+year;
output.dtf.setTextFormat(someTextFormat);
eventObj.target._x = 1105;
eventObj.target._y = 166;
// or delete the dataChosser
cal.removeMovieClip();
};
cal.testDateChooser.addEventListener("change", listenerObj);
}
// create a place to show output
this.createEmptyMovieClip("output", this.getNextHighestDepth());
this.output.drawTextBox("OUTPUT : ", 400, 30, 180, 0, 0xFF0000, 0xffffff);
// create a button to pic the date
this.createEmptyMovieClip("da_btn", this.getNextHighestDepth());
//,,,,,,,,,,makeButton(..name........ func to exec
this.da_btn.makeButton("PICK DATE", "selectDate");


DIR -- new FLA ....paste code ....drag datechooser to stage and delete ... publish ... and it works... i think .. i know nothing........

fsumanning
02-10-2005, 02:13 PM
I tried what you gave and it works for the first time a user selects a date. I rearranged some of my code so that it was fashioned after yours and still got the error. There must be something basic that I'm doing wrong.

I would like to keep the code as follows due to it being relatively clean.

The function to perform the work:

function selectDate(textBox){
testDateChooser.setStyle("fontSize", "15");
testDateChooser.selectableRange = {rangeStart:new Date()};
testDateChooser.disabledDays = [0,6];
testDateChooser.scaleX = 210;
testDateChooser.scaleY = 210;
testDateChooser._x = 180;
testDateChooser._y = 120;

var listenerObj:Object = new Object();
listenerObj.change = function (eventObj:Object){
trace("Detected and Date change...");

var month = eventObj.target.selectedDate.getMonth()+1;
var day = eventObj.target.selectedDate.getDate();
var year = eventObj.target.selectedDate.getFullYear();

if(month < 10) {month = "0" + month;}
if(day < 10) {month = "0" + day;}
var formattedDate:String = month + "/" + day + "/" + year;

//alert(formattedDate);
textBox.text = formattedDate;

eventObj.target._x = 1105;
eventObj.target._y = 166;
}
testDateChooser.addEventListener("change", listenerObj);
}

and the button code to call the function providing the name of the textbox to edit:

on(release){
selectDate(buildInspDate_txt);
}

Last night I created a test fla file and it has the same problem (at least I am consistent). I can e-mail you the fla file... I don't really have a place to post it on the web.

scot
02-10-2005, 03:07 PM
email it to [email protected]

cancerinform
02-10-2005, 03:55 PM
I think you have to eliminate the _global var, since global may interfere with the datechooser. I have been working with the datechooser for one week now and also had alert boxes and serverside scripts and have never observed this so far.

fsumanning
02-10-2005, 05:40 PM
I have been enlightened! My buddy here at work has a step-son that does a good deal of Flash. He took my example and quickly found its fault. I've had this particular method in ALL of the examples I've been working on:

_global.Object.prototype.alert = function (message) {
getURL("javascript:alert('"+message+"')");
}

Turns out that the line

getURL("javascript:alert('"+message+"')");

was causing the problem all along, even though it was not used in the code.

Now the problem is, other portions of my "production" flash app use that line. I'll have to go about that in another way.

Thanks to scot and cancerinform for your help.

I'll still e-mail the app to you scot, just because.

Thanks again!

scot
02-10-2005, 07:18 PM
instead of making your alert function a prototype ... just make it a regular function .. and should get rid of the bug and allow you to use finc in the rest of your app