Search code examples
apache-flexflashvars

FlashVars in Flex, getting error?


I changed my html template to include flashvars like so:

if (hasRequestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    AC_FL_RunContent(
            "src", "${swf}",
            "FlashVars", "product_id=4958",
            "width", "${width}",
            "height", "${height}",
            "align", "middle",
            "id", "${application}",
            "quality", "high",
            "bgcolor", "${bgcolor}",
            "name", "${application}",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );
  }

And I am trying to access them in my app like so:

private static var _PID:uint = Application.application.parameters.product_id;

But I am getting this error:

Error #1009: Cannot access a property or method of a null object reference.

I do not know why? Any ideas? Is this just happening because I am in the flex debugger?

Thanks!!


Solution

  • I'll bet it's because this is a static variable - the assignment is probably happening before the app is initialized.

    Try assigning the value to _PID inside of a creationComplete handler instead; then the application is guaranteed to be initialized.