A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Error #1009: Cannot access

  1. #1
    Senior Member
    Join Date
    Jun 2003
    Posts
    231

    Error #1009: Cannot access

    Newbe here. And I need help. I bought Tiltviewer and trying to get it integrated into my cs3 site. I am getting this error when loading it in though XML

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

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at flash_embed_fla::MainTimeline/setOptions()

    Help!

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Is setOptions part of your code or part of tiltviewer? If it's part of tiltviewer, you'll probably have to ask for the author's help/support.

  3. #3
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    It's located in the movie being loaded.

  4. #4
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    Doesn't make much sense, it works fine when viewing the movie that is being loaded directly but once it gets loaded that when I get that error and shows up blank

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    That doesn't really answer my question. Did you create that movie, or is it part of Tiltviewer?

    One common cause of this error when it occurs like this is attempting to access the stage or root before the item is on the displaylist. It works in standalone because in that case stage and root are set from the very beginning, but when loading into another movie those properties are null until put on the displaylist.

    If you have code in a constructor function which references the stage or root, move it into a function which is a listener for Event.ADDED_TO_STAGE.

  6. #6
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    Tiltviwer gives you a example file of how you can load it externally so I was loading that file. All that option code is in that container file.

    This is the code in the container file that is loading tiltviewer (the file we are loading to the main file)

    /**
    * TILTVIEWER FLASH EMBED EXAMPLE CODE
    * For documentation visit: http://www.airtightinteractive.com/p.../pro/docs.html
    **/

    import flash.display.*;
    import flash.net.URLRequest;

    //turn off stage auto resizing
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;

    //load TiltViewer SWF
    var ldr:Loader = new Loader();
    addChild(ldr);
    var url:String = "TiltViewer.swf";
    var urlReq:URLRequest = new URLRequest(url);
    ldr.load(urlReq);


    //SET TILTVIEWER OPTIONS
    //Set tilviewer options here.
    //These options will override options set via the HTML flashvars.
    // For a description of config options, go to:
    // http://www.airtightinteractive.com/p...g_options.html
    ldr.contentLoaderInfo.addEventListener(Event.INIT, setOptions);
    function setOptions(e:Event){
    var options:Object = Object(ldr.content).embedOptions;
    //Set example options here
    options.columns = 3;
    options.rows = 2;
    options.useReloadButton = false;
    options.bkgndTransparent = true;
    options.useFlickr = false;
    options.xmlURL = "gallery.xml";
    options.maxJPGSize = 640;
    options.bkgndTransparent = true;
    }


    //OPTIONAL TILTVIEWER RESIZING
    //By default TiltViewer will autosize to fill the stage
    //If you want to give TiltViewer a specific postion and size uncomment the following block:
    /*
    stage.addEventListener(Event.ENTER_FRAME,resizeTil tViewer);
    function resizeTiltViewer(e:Event){
    //example tiltViewer size and position values
    var tvWidth = stage.stageWidth/2;
    var tvHeight = stage.stageHeight/2;
    var tvX = stage.stageWidth/4;
    var tvY = stage.stageHeight/4;
    ldr.x = tvX;
    ldr.y = tvY;
    var tiltviewer = Object(ldr.content)._app;
    if ( tiltviewer != null){
    tiltviewer.autoSize = false;
    tiltviewer.setSize(tvWidth,tvHeight);
    }
    }
    */


    //OPTIONAL TILTVIEWER MASKING
    //if you want to mask TiltViewer uncomment the following block:
    /*
    var tiltviewerMask:Sprite = new Sprite();
    ldr.mask = tiltviewerMask;
    stage.addEventListener(Event.RESIZE,resizeMask);
    resizeMask(null);
    function resizeMask(e:Event){

    var tvWidth = stage.stageWidth/2;
    var tvHeight = stage.stageHeight/2;
    var tvX = stage.stageWidth/4;
    var tvY = stage.stageHeight/4;

    tiltviewerMask.graphics.clear();
    tiltviewerMask.graphics.beginFill(0xff00ff,1);
    tiltviewerMask.graphics.drawRect(tvX, tvY, tvWidth, tvHeight);
    }
    */



    //example background resizing code
    stage.addEventListener(Event.RESIZE,onResize);
    onResize(null);
    //called on stage resize
    function onResize(e:Event){
    mcBkgnd.width = stage.stageWidth;
    mcBkgnd.height = stage.stageHeight;
    }

  7. #7
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    This is my main AS file

    package com
    {
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.text.TextFieldAutoSize;
    import fl.motion.Color;
    import flash.geom.ColorTransform;
    import com.background.*;
    import com.background.slideshow.*;
    import com.menu.*;
    import com.utils.*;
    import com.media.Mp3;
    import gs.TweenLite;
    import gs.easing.*;

    import flash.text.*;

    /////////////////SWF ADDRESS CLASSES////////////////////
    /**/ import com.asual.swfaddress.SWFAddress; /**/
    /**/ import com.asual.swfaddress.SWFAddressEvent; /**/
    /**/ /**/
    /**//* SOURCE: http://www.asual.com/swfaddress/ *//**/
    ////////////////////////////////////////////////////////

    public class Main extends MovieClip
    {
    private var siteTitle:String;

    // background Objects
    private var pattern:Pattern; //pattern over video
    private var img:Slideshow;
    private var swf:Swf;
    private var bgHolder:Sprite;
    private var logo:*;
    private var bgColor:BgColor;
    private var menu:Menu;
    private var preloader:Preloader;

    //Mute BT
    private var mute:Mute;
    //Fullscreen Bt
    private var fullscreen:Fullscreen;

    private var loadModule:Loader; //loader for the different modules;
    private var currentModule:*;
    private var xmlPath:String;
    private var menuIsAdded:Boolean=false;

    private var logoXposition;
    private var logoYposition;

    public function Main()
    {
    // stage setup
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;
    stage.addEventListener(Event.RESIZE, onStageResize);

    preloader = new Preloader;
    addChild(preloader);
    preloader.visible = false;

    this.loaderInfo.addEventListener(ProgressEvent.PRO GRESS, loadingProgress);
    this.loaderInfo.addEventListener(Event.COMPLETE, loadingComplete);


    }

    private function loadingProgress(e:Event):void
    {
    var percentLoaded = (this.loaderInfo.bytesLoaded/this.loaderInfo.bytesTotal)*100;
    }

    private function loadingComplete(e:Event)
    {

    this.loaderInfo.removeEventListener(Event.COMPLETE , loadingComplete);
    this.loaderInfo.removeEventListener(ProgressEvent. PROGRESS, loadingProgress);
    this.play();
    getConfiguration();
    }



    private function getConfiguration():void
    {
    GlobalVarContainer.vars.XML_PATH = 0;

    var loadXml = new LoadXml("xml/config.xml");
    loadXml.addEventListener(Event.COMPLETE, setLayout, false, 0, true);
    }


    private function setLayout(e:Event):void
    {
    var list:XMLList = new XMLList(e.target.returnData);
    var menuXposition = list.menuXposition;
    var menuYposition = list.menuYposition;
    var contentYposition = list.contentYposition;
    logoXposition = list.logoXposition;
    logoYposition = list.logoYposition;

    loadBg(list);

    // Bottom shape color
    var logo:String = list.logo.text();

    // Keeps site title that appears on html page
    siteTitle = e.target.returnData.siteTitle.text();

    // This listener detects when the URL has changed
    SWFAddress.addEventListener(SWFAddressEvent.CHANGE , handleSWFAddressChange);

    //Load logo
    var loadImg:LoadImgs;
    loadImg = new LoadImgs (logo);
    loadImg.addEventListener(Event.COMPLETE, onLogoComplete);

    menu = new Menu();
    addChild(menu);
    menu.x = menuXposition;
    menu.y = menuYposition;
    menu.addEventListener(Event.ADDED, onAddedMenu);


    // check if there is a mp3 file to play
    if(list.sound!="")
    {
    // add Mute mc to stage
    mute = new Mute;
    addChild(mute);
    //play mp3
    Mp3.play(list.sound.text());
    }

    // add fullscreen button to stage and the event listener
    fullscreen = new Fullscreen;
    addChild(fullscreen);
    fullscreen.addEventListener(MouseEvent.CLICK, fullScreenOn);

    loadModule = new Loader();
    addChild(loadModule);
    loadModule.contentLoaderInfo.addEventListener(Prog ressEvent.PROGRESS, onloadModuleProgress);
    loadModule.contentLoaderInfo.addEventListener(Even t.COMPLETE, onLoadModuleComplete);
    loadModule.y = contentYposition;

    this.setChildIndex(preloader, numChildren-1);

    onStageResize();
    }


    private function onAddedMenu (ev:Event):void
    {
    menu.removeEventListener(Event.ADDED, onAddedMenu);
    menuIsAdded = true;
    }

    // logo is completely loaded
    private function onLogoComplete (e:Event):void
    {
    addChildAt(e.target.returnData,2);
    logo = e.target.returnData;
    logo.x = logoXposition;
    logo.y = logoYposition;
    }

    /* *****************************
    Method load Modules
    ***************************** */

    public function onLoadModule(swf:String, xml:String):void
    {
    if(xml == GlobalVarContainer.vars.XML_PATH)
    {

    try{ currentModule.getSWFAdressInfo(); }
    catch (err:Error){ trace("no getSWFAdressInfo() function on loaded module"); }

    return;
    }

    preloader.visible = true;
    loadModule.load(new URLRequest(swf));
    GlobalVarContainer.vars.XML_PATH = xml;
    }

    private function onloadModuleProgress(e:ProgressEvent):void
    {
    var percentLoaded:Number = e.bytesLoaded/e.bytesTotal;
    percentLoaded = Math.round(percentLoaded * 100);
    preloader.txt.text=percentLoaded + "%";
    }


    private function onLoadModuleComplete(e:Event):void
    {
    currentModule = e.target.content;
    preloader.visible = false;
    preloader.txt.text = "0%";
    loadModule.addEventListener(Event.ADDED, alignModule);
    }


    private function handleSWFAddressChange(e:SWFAddressEvent)
    {
    var title:String = siteTitle;
    var pathNames:Array = SWFAddress.getPathNames();
    for (var i = 0; i < pathNames.length; i++)
    title += " - " + String(pathNames[i].substr(0, 1).toUpperCase() + pathNames[i].substr(1)).split("-").join(" ");
    SWFAddress.setTitle(title);

    if(menuIsAdded)
    menu.getItem(e.value.substring(1));
    }

    /* *****************************
    End Method load Modules
    ***************************** */



    /* *****************************
    Method load Background
    ***************************** */

    private function loadBg(list:XMLList):void
    {
    var type:String = list.background.@type;

    bgHolder = new Sprite();
    addChild(bgHolder);


    // if there is a backgroung color add it to stage
    if(list.bgColor!="")
    {
    bgColor = new BgColor;
    bgHolder.addChild(bgColor);
    setColor(bgColor, list.bgColor.text(), 1);
    bgColor.width = stage.stageWidth;
    bgColor.height = stage.stageHeight;
    }

    // check if there is and bg asset to add to stage
    if(list.background!="")
    {
    //check bg type;
    switch (type) {

    case "img" :
    img = new Slideshow(list.background);
    bgHolder.addChild(img);
    break;

    case "swf" :
    swf = new Swf(list.background.asset[0].text());
    bgHolder.addChild(swf);
    break;
    }
    }

    if(list.pattern != "")
    {
    pattern = new Pattern(list.pattern.text(), stage.stageWidth, stage.stageHeight);
    bgHolder.addChild(pattern);
    }
    }

    /* *****************************
    End Method load Background
    ***************************** */



    private function onStageResize (ev:Event=null):void
    {

    if(fullscreen)
    {
    // align fullscreen bt
    fullscreen.x = int(stage.stageWidth - fullscreen.width - 10);
    fullscreen.y = 10;
    }

    if(mute!=null)
    {
    mute.x = int(fullscreen.x - mute.width - 5);
    mute.y = 10;
    }

    if(preloader)
    {
    preloader.y = int(stage.stageHeight / 2 - preloader.height / 2);
    preloader.x = int(stage.stageWidth / 2 - preloader.width / 2);
    }

    if(bgColor!=null)
    {
    bgColor.width = stage.stageWidth;
    bgColor.height = stage.stageHeight;
    }

    alignModule();
    }

    //align module
    private function alignModule(e:Event=null):void
    {
    if(logo && menu)
    {

    if(logo.x+logo.width > menu.x+menu.width)
    {
    loadModule.x = int(stage.stageWidth / 2 - loadModule.width / 2);
    if(loadModule.x < logo.x + logo.width+50) loadModule.x = int((logo.x + logo.width)+50);
    }

    if(logo.x+logo.width < menu.x+menu.width)
    {
    loadModule.x = int(stage.stageWidth / 2 - loadModule.width / 2);
    if(loadModule.x < menu.x + menu.width + 50) loadModule.x = int((menu.x + menu.width)+50);
    }

    }
    }

    // change objects color
    private function setColor(mc:Sprite, color:Number, opacity:Number):void
    {
    var tint:Color = new Color();
    tint.setTint(color, opacity);
    mc.transform.colorTransform = tint;
    }


    /* *****************************
    Method set Fullscreen
    ****************************** */

    // set stage to fullscreen;
    function fullScreenOn(e:MouseEvent):void
    {
    stage.displayState = StageDisplayState.FULL_SCREEN;
    fullscreen.removeEventListener(MouseEvent.CLICK, fullScreenOn);
    fullscreen.addEventListener(MouseEvent.CLICK, fullScreenOff);
    }

    // set stage to normal screen;
    function fullScreenOff(e:MouseEvent):void
    {
    stage.displayState = StageDisplayState.NORMAL;
    fullscreen.addEventListener(MouseEvent.CLICK, fullScreenOn);
    fullscreen.removeEventListener(MouseEvent.CLICK, fullScreenOff);
    }

    /* *****************************
    End Method set Fullscreen
    ****************************** */


    }
    }

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Because the error appears to be thrown in the setOptions function, the only cause I can see is that the embedOptions property is not set yet when it runs. According to the livedocs, it should be when the init event is fired, but it's possible that that is set on a frame other than the first.

    Put a trace in setOptions to confirm:
    Code:
    function setOptions(e:Event){
      var options:Object = Object(ldr.content).embedOptions;
      trace("options is: "+options);
      //Set example options here
      options.columns = 3;
      options.rows = 2;
      options.useReloadButton = false;
      options.bkgndTransparent = true;
      options.useFlickr = false;
      options.xmlURL = "gallery.xml";
      options.maxJPGSize = 640;
      options.bkgndTransparent = true;
    }
    and if that is the case, change Event.INIT to Event.COMPLETE
    Code:
    ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, setOptions);

  9. #9
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    No go. Still getting the same issue, just to confirm this is what that snippet should look like

    //SET TILTVIEWER OPTIONS
    //Set tilviewer options here.
    //These options will override options set via the HTML flashvars.
    // For a description of config options, go to:
    // http://www.airtightinteractive.com/p...g_options.html
    ldr.contentLoaderInfo.addEventListener(Event.COMPL ETE, setOptions);
    function setOptions(e:Event){
    var options:Object = Object(ldr.content).embedOptions;
    trace("options is: "+options);
    //Set example options here
    options.columns = 3;
    options.rows = 2;
    options.useReloadButton = false;
    options.bkgndTransparent = true;
    options.useFlickr = false;
    options.xmlURL = "gallery.xml";
    options.maxJPGSize = 640;
    options.bkgndTransparent = true;
    }

  10. #10
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Are you sure it's the same error? Including
    "at flash_embed_fla::MainTimeline/setOptions()"?

    What did the trace say?

  11. #11
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    Same error.
    The trace says this: options is: [object Object]

  12. #12
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    It actually now says

    options is: null
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at flash_embed_fla::MainTimeline/setOptions()

  13. #13
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Well, that at least makes sense. It's throwing the null error because the embedOptions property isn't set yet. Sounds like a bug in Tiltviewer.

    But to be clear, there are 3 layers of swfs here, right? Main, tiltviewer embedder, and tiltviewer?

    And the tiltviewer embedder works on its own?

  14. #14
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    Yes your correct on that, 3 layers, and embedder works perfectly on it's own..

  15. #15
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Without knowing how embedOptions gets set, it's pretty much impossible to debug. It's weird that it would work loading into the embedder but not when that is itself embedded.

    It's possible/probable that tiltviewer is looking at the parent's loaderinfo for flashvars and not finding anything, it fails to set embedOptions correctly.

    You could mask the error by checking whether options is null and if it is set it yourself.
    Code:
    ldr.contentLoaderInfo.addEventListener(Event.INIT, setOptions);
    function setOptions(e:Event){
      var options:Object = Object(ldr.content).embedOptions;
      if (options == null){
        options = {};
        Object(ldr.content).embedOptions = options;
      }
      //Set example options here
      options.columns = 3;
      options.rows = 2;
      options.useReloadButton = false;
      options.bkgndTransparent = true;
      options.useFlickr = false;
      options.xmlURL = "gallery.xml";
      options.maxJPGSize = 640;
      options.bkgndTransparent = true;
    }
    That should prevent that particular error, but there's no guarantee that it will actually use those options correctly.

  16. #16
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    That did work on preventing the error but nothing shows up still.. Would it help if I got you the files to look at?

  17. #17
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    I doubt you have the rights to redistribute the Tiltviewer source, if you even have it. And if you don't have it, I don't think looking at the files will tell me anything you haven't posted already.

    I think your best course of action is either to eliminate the middle layer and load tiltviewer directly from the main movie, or get support from the author.

  18. #18
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    They don't give you the actual FLA for tilt viewer and it's free anyway, they give you a example FLA on how to load their SWF. I asked the author they seemed very unhelpful they did say to try and load tiltviewer.swf directly and use the code from the example file they gave me but I have no clue where to pop all that code in, my main FLA has no code in just in that AS file and i'm really really new to AS3, i'm a seasoned as2 flash designer

  19. #19
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You should be able to take the code from the sample and shove it in a frame on your main timeline. If you want to do it in code, then take this part:
    Code:
    //load TiltViewer SWF
    var ldr:Loader = new Loader();
    addChild(ldr);
    var url:String = "TiltViewer.swf";
    var urlReq:URLRequest = new URLRequest(url);
    ldr.load(urlReq);
    
    //SET TILTVIEWER OPTIONS
    //Set tilviewer options here.
    //These options will override options set via the HTML flashvars.
    // For a description of config options, go to:
    // http://www.airtightinteractive.com/p...g_options.html
    var setOptions:Function = function(e:Event){
      var options:Object = Object(ldr.content).embedOptions;
      //Set example options here
      options.columns = 3;
      options.rows = 2;
      options.useReloadButton = false;
      options.bkgndTransparent = true;
      options.useFlickr = false;
      options.xmlURL = "gallery.xml";
      options.maxJPGSize = 640;
      options.bkgndTransparent = true;
    }
    ldr.contentLoaderInfo.addEventListener(Event.INIT, setOptions);
    and put it in in place of loading the embedder.

  20. #20
    Senior Member
    Join Date
    Jun 2003
    Posts
    231
    No luck here either. I hate as3

    With that I get this error

    TypeError: Error #1010: A term is undefined and has no properties.
    at MethodInfo-275()


    The problem is my files are being called from a XML file, so inserting that load swf in the main timeline wont work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center