Skip to main content
Participating Frequently
February 15, 2014
Answered

Please HELP Me With This! Error 1046!

  • February 15, 2014
  • 1 reply
  • 1458 views

I cannot figure out what my problem is. When I check for errors its is not telling me any. But when I run it, it is saying: 1046: This was not found or was not a compile-time constant: home2.

import flash.events.MouseEvent;

import flash.display.Loader;

import flash.net.URLRequest;

import flash.events.Event;

var loadvar:Loader = new Loader();

var home1 = loadvar;

home1.load(new URLRequest("img/home1.jpg"));

home1.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

var home2 = loadvar;

home2.load(new URLRequest("img/home2.jpg"));

home2.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(e:Event):void

{

var img:Bitmap = Bitmap(e.target.content);

img.width = 100;

img.height = 100;

};

thumb1.addChild(home1);

thumb2.addChild(home2);

But it is working when I take our everything that has to do with home2.

This topic has been closed for replies.
Correct answer kglad

you're assigning the same loader to three different instance names, loadvar, home1 and home2.  and you only have one loader while you need two if you want to see home1.jpg and home.jpg at the same time:

use:

import flash.events.MouseEvent;

import flash.display.Loader;

import flash.net.URLRequest;

import flash.events.Event;

var home1:Loader=new Loader();

home1.load(new URLRequest("img/home1.jpg"));

home1.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

var home2:Loader=new Loader();

home2.load(new URLRequest("img/home2.jpg"));

home2.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(e:Event):void

{

var img:Bitmap = Bitmap(e.target.content);  // this does nothing useful.

img.width = 100;

img.height = 100;

};

thumb1.addChild(home1);

thumb2.addChild(home2);

// both will now load but you won't see both because they are positioned on top of each other.  ie, offset one of them.

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
February 15, 2014

you're assigning the same loader to three different instance names, loadvar, home1 and home2.  and you only have one loader while you need two if you want to see home1.jpg and home.jpg at the same time:

use:

import flash.events.MouseEvent;

import flash.display.Loader;

import flash.net.URLRequest;

import flash.events.Event;

var home1:Loader=new Loader();

home1.load(new URLRequest("img/home1.jpg"));

home1.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

var home2:Loader=new Loader();

home2.load(new URLRequest("img/home2.jpg"));

home2.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

function onComplete(e:Event):void

{

var img:Bitmap = Bitmap(e.target.content);  // this does nothing useful.

img.width = 100;

img.height = 100;

};

thumb1.addChild(home1);

thumb2.addChild(home2);

// both will now load but you won't see both because they are positioned on top of each other.  ie, offset one of them.

Participating Frequently
February 15, 2014

That was actually my first choice. I set a new variable to see if it would make a difference. I just used the code you gave me and I am still getting the same problem.

kglad
Community Expert
Community Expert
February 15, 2014

that error's not from the code i suggested.

click file>publish settings>swf and tick "permit debugging".  retest.

the problematic line number will be in the error message.