• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Why would this line not work?

New Here ,
Mar 23, 2011 Mar 23, 2011

Copy link to clipboard

Copied

I am trying to figure out how to call an onComplete function without  leaving the code loop (because the vars are no longer recognized with  the hand-off). I thought this might work:


imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(){DisplayObjectContainer(master_mc.getChildAt(i)).addChild(imgLoader);});

But alas, I get a nice error I am unfamilar with:

Scene 1, Layer 'Layer 3', Frame 1, Line 83     1178: Attempted access of inaccessible property master_mc through a reference with static type mouseGallery3_fla:MainTimeline.

What is the problem and is it just not the right thing to try? Any help would be kindly welcome. Thanks.

TOPICS
ActionScript

Views

823

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 23, 2011 Mar 23, 2011

Copy link to clipboard

Copied

hi

firstly, i advise not putting functions inline. try this instead:

imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);

function completeHandler(event:Event):void

{

     DisplayObjectContainer(master_mc.getChildAt(i)).addChild(imgLoader);

}

this should fix your problem - if not, you'll need to post more of your project

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2011 Mar 23, 2011

Copy link to clipboard

Copied

Thanks Lee.  Your way is actually what I previously had been doing.

The issue is that I am accessing variables inside the init function that can't be accessed when the onComplete runs an outside function. I very well may be doing this incorrectly and would greatly value any help. Basically I can't figure out how to send an argument (like the var i for example) in the onComplete event function.

Here are the init and event functions:

function init(e:Event = null):void
{

    removeEventListener(Event.ADDED_TO_STAGE, init);

    var boxSet:Object = new Object();

    for (var i:int = 1; i < boxCount; i++)
    {
        boxSet = new Sprite();

        with (boxSet)
        {
            master_mc.graphics.beginFill(0xff1133);
            master_mc.graphics.drawRect(nextXPos, 0, boxWidth, boxHeight+boxMargin);
            master_mc.y = 130;
            master_mc.addChild(boxSet);
           
            x = nextXPos;

            imgLoader = new Loader();
            imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, addThumbnail);
            imgLoader.load(new URLRequest("images/test_img0" + i + ".png"));

            this.addEventListener(MouseEvent.CLICK, doButton);
        }

   
        nextXPos = i*(boxWidth+boxMargin);

    }   // END for loop...
   
    stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

    master_mc.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler);
    master_mc.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler);
}


function addThumbnail(event:Event):void
{
    DisplayObjectContainer(master_mc.getChildAt(7)).addChild(imgLoader);
    removeEventListener(Event.COMPLETE, addThumbnail);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 23, 2011 Mar 23, 2011

Copy link to clipboard

Copied

There is no reason you can't add the loader child to the display list when it is created. You don't have to wait for the complete event to do that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

   I didn't know that. So what is the purpose in using an image load onComplete? I seem to see it often. I guess I could use an onError event to make sure everything was captured if something did not load.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

  Also, what is the reason for the error 1178: Attempted access of inaccessible property above? While I can do something different, that looked like a public/private package var issue. I'm not writing any classes but only code in the flash file. Please help me understand. Thanks...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

in your code you reference master_mc:

with (boxSet)
        {
            master_mc.graphics.beginFill(0xff1133);

but boxSet.master_mc does not exist

re error 1178, what is on line 83 where the error occured?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 24, 2011 Mar 24, 2011

Copy link to clipboard

Copied

LATEST

The purpose of the Complete event is to know when loading is complete.

Maybe you want to fade in the loaded asset. Well you need to know when that is complete so that you can start the fade. In that case you could attach the loader and make it invisible until it was done.

Or maybe you need to size the image after loading. You won't be able to know the size until it is loaded so you have to wait.

Maybe you are showing some kind of loading animation or such and you will need to know when to stop it.

There are a million other reasons to want to know when loading is done.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines