# Access dynamic fields on stage from MC

**URL:** <https://forum.kirupa.com/t/access-dynamic-fields-on-stage-from-mc/324240>\
**Category:** flash\
**Created:** [August 10, 2011, 3:00am UTC](https://forum.kirupa.com/t/access-dynamic-fields-on-stage-from-mc/324240 "2011-08-10T03:00:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hyperhappy](https://avatars.discourse-cdn.com/v4/letter/h/b5e925/32.png) [@hyperhappy](https://forum.kirupa.com/u/hyperhappy)\
**Post date:** [August 10, 2011, 3:00am UTC](https://forum.kirupa.com/t/access-dynamic-fields-on-stage-from-mc/324240/1 "2011-08-10T03:00:40Z")

</div>

Hello fellow flashers!

I am running a script in a movieclip that captures date and time but the actual fields are on the \_root or the stage. How to I access my dynamic fields? I put the prefix stage. in front of the instance name but I am getting the errors on all the places where I am trying to access the instance name “Symbol ‘date-time’, Layer ‘Layer 1’, Frame 1, Line 14 1119: Access of possibly undefined property ampm2 through a reference with static type flash.display:Stage.” Here’s the code:

flash.display.Stage

//==== TIME ==== //

// This line puts the date object into a variable we can use more easily  
var now:Date = new Date();  
// These 3 lines put the hours, minutes, and seconds into variables  
var hours = now.getHours();  
var minutes = now.getMinutes();  
// Conditional statement to set AM or PM according to hour(military time)  
if (hours \>= 12)  
{  
stage.ampm1.text = “PM”;  
stage.ampm2.text = “PM”;  
stage.ampm3.text = “PM”;  
}  
else  
{  
stage.ampm1.text = “PM”;  
stage.ampm2.text = “PM”;  
stage.ampm3.text = “AM”;  
}  
// Conditional that converts military time to standard time display  
if (hours \> 12)  
{  
hours = hours - 12;  
}  
if (hours == 00)  
{  
hours = 12;  
}  
// Conditional that adds 0 to the front of any hour less than 10  
if (hours \< 10)  
{  
stage.hours1.text = hours;  
stage.hours2.text = hours;  
stage.hours3.text = hours;  
}  
else  
{  
stage.hours1.text = hours;  
stage.hours2.text = hours;  
stage.hours3.text = hours;  
}  
// Conditional that adds 0 to the front of any minute less than 10  
if (minutes \< 10)  
{  
stage.minutes1.text = “0” + minutes;  
stage.minutes2.text = “0” + minutes;  
stage.minutes3.text = “0” + minutes;  
}  
else  
{  
stage.minutes1.text = minutes;  
stage.minutes2.text = minutes;  
stage.minutes3.text = minutes;  
}

var format1:TextFormat = new TextFormat();  
format1.letterSpacing = -20;  
stage.hours3.setTextFormat(format1);  
stage.minutes3.setTextFormat(format1);

//==== DATE ==== //;

//Array to hold a list of the weekdays.;  
var weekdays:Array = new Array (“Sun”,“Mon”,“Tue”,“Wed”,  
“Thu”,“Fri”,“Sat”);

//Array to hold a list of the months.  
var months:Array = new Array (“Jan”,“Feb”,“Mar”,“Apr”,“May”,“Jun”,“Jul”,  
“Aug”, “Sep”, “Oct”,“Nov”,“Dec”);

//Retrieve the day, month and year from the date class.  
var theDay = weekdays[now.getDay()];  
var theMonth = months[now.getMonth()];  
var theDate = now.getDate();

stage.date1.text = theDay + ", " + theMonth + " " + theDate;  
stage.date2.text = theDay + ", " + theMonth + " " + theDate;

Any help would be greatly appreciated!

Have a good one!=
