Hi everyone, I’m still extremely new to as3, I’m just now learning the new object oriented way of scripting. It’s been a wild ride, but I’ve finally learned how to keep script off my frames (very hard coming from as2).
Here’s my problem:
I have a TextField on the stage in my main .fla file named loadPercent.
I’m loading a jpg with preLoad.as and displaying the bytes loaded in loadPercent.
I can access my loadPercent TextField from my MainClass
but I can’t access it from preLoad.as
the document class is MainClass.as
package
{
import flash.display.MovieClip;
import preLoad;
public class MainClass extends MovieClip
{
public function MainClass()
{
trace ("DOCUMENT CLASS CREATED");
//loadPercent.text = "test"; // this works
var loader:preLoad = new preLoad("Cerulean.jpg",177.5,150,1,1,0);
}
}
}
I know that most of the open brackets({) go on the same line as the function definition, but it’s easier for me to visualize my scope this way.
preLoad.as
package
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.ProgressEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;
import flash.display.Stage;
//import flash.display.DisplayObject;
//import flash.display.DisplayObjectContainer;
public class preLoad extends Sprite
{
public function preLoad(imageName, xpos, ypos, xscale, yscale, shadowOnOff)
{
trace("ENTERING PRELOAD");
var myRequest:URLRequest = new URLRequest(imageName);
trace(myRequest);
var myLoader:Loader = new Loader();
trace(myLoader);
if(shadowOnOff == 1)
{
import flash.filters.*;
var myShadow:DropShadowFilter = new DropShadowFilter();
myShadow.distance = 0;
myShadow.color = 0x000000;
myShadow.blurX = 10;
myShadow.blurY = 10;
myShadow.quality = 3;
myLoader.filters = [myShadow];
}
myLoader.load(myRequest);
myLoader.contentLoaderInfo.addEventListener(Event.OPEN,showPreloader);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,showProgress);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,showLoadResult);
//myLoader.contentLoaderInfo.addEventListener(Event.UNLOAD,unLoadResult);
function showPreloader(evt:Event):void
{
loadPercent.visible = true;
trace("LOADING: " + imageName);
}
function showProgress(evt:ProgressEvent):void
{
loadPercent.text = (Math.floor((evt.bytesLoaded/evt.bytesTotal)*100)) + "";
}
function showLoadResult(evt:Event):void
{
loadPercent.visible = false;
myLoader.alpha = 0;
myLoader.x = xpos;
myLoader.y = ypos;
myLoader.scaleX = xscale;
myLoader.scaleY = yscale;
addChild(myLoader);
var myTween:Tween = new Tween(myLoader, "alpha", Regular.easeOut, 0, 1, .5, true);
}
}//preLoad
}//class
}//package
I get three ‘#1120 access of undefined propery’ errors for each time i try to access loadPercent.
I’m sure I’m overlooking something because I’m a newb, I’d appreciate any help
a few basic questions:
-
all my files are in a folder in my documents, not in the flash directory, is this bad? I’ve seen people using com.whatever etc.
-
my main .fla file does not share the same name as my MainClass.as
(it’s not named MainClass.fla) Is that a problem?
I’m assuming these are inconsequential because my code seems to work up to a certain point.
again thanks for any advice.