# Assigning values to variables

**URL:** <https://forum.kirupa.com/t/assigning-values-to-variables/201858>\
**Category:** Uncategorized\
**Created:** [September 25, 2006, 7:37pm UTC](https://forum.kirupa.com/t/assigning-values-to-variables/201858 "2006-09-25T19:37:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![benny\_hill](https://avatars.discourse-cdn.com/v4/letter/b/b5e925/32.png) [@benny\_hill](https://forum.kirupa.com/u/benny_hill)\
**Post date:** [September 25, 2006, 7:37pm UTC](https://forum.kirupa.com/t/assigning-values-to-variables/201858/1 "2006-09-25T19:37:06Z")

</div>

How do I assign a timeline variable a value within a function? I tried declaring the variable on the main timeline:

```
  var dynamicHeight:Number;

```

then inside a function I write:

```
  dynamicHeight = (RootNode.childNodes.length)*160;

```

But when I write:  
trace(dynamicHeight)

on the timeline I always get “Undefined”. But when I place the trace action inside the function where dynamicHeight is it comes back 1760 like it is suppose to.

I know the problem is scope, but why can’t I assign new values to a timeline variable from within a function or if/then statement?
