|
-
Using text variables
Hi... I hope you don't think I'm stupid now, but I just can't get my head around this..
I think what I'm having trouble is conditional statements about string variables... Like if (lastChange == "bild1child"). Is that the way to do it?
Code:
/*
This is going to use variables loaded from the html-file later, like:
banner.swf?bild1=/bilder/banner1&bild2=/bilder/banner2&bild3=/bilder/banner3
but now they are predefined for error-testing
*/
var bild1:String = "/bilder/april.jpg"
var bild2:String = "/bilder/avril.jpg"
var bild3:String = "/bilder/pastill.jpg"
var bild1Request:URLRequest = new URLRequest(bild1);
var bild1Loader:Loader = new Loader();
bild1Loader.load(bild1Request);
bild1Loader.x = 0;
bild1Loader.y = 0;
var bild2Request:URLRequest = new URLRequest(bild2);
var bild2Loader:Loader = new Loader();
bild2Loader.load(bild2Request);
bild2Loader.x = 0;
bild2Loader.y = 0;
var bild3Request:URLRequest = new URLRequest(bild3);
var bild3Loader:Loader = new Loader();
bild3Loader.load(bild3Request);
bild3Loader.x = 0;
bild3Loader.y = 0;
var bildTimer:Timer = new Timer(3000);
bildTimer.addEventListener(TimerEvent.TIMER, changeBild);
addChild(bild1Loader);
var lastChange:String = "bild1child";
function changeBild(event:TimerEvent):void
{
trace("det funkar " + lastChange);
if (lastChange == "bild1child")
{
removeChild(bild1Loader);
addChild(bild2Loader);
var lastChange:String = "bild2child";
}
else if (lastChange == "bild2child")
{
removeChild(bild2Loader);
addChild(bild3Loader);
var lastChange:String = "bild3child";
}
else if (lastChange == "bild3child")
{
removeChild(bild3Loader);
addChild(bild1Loader);
var lastChange:String = "bild1child";
}
}
bildTimer.start();
Thanks for your time!
-
i don't see anything wrong in your code on a quick glance. Are you getting an error? You might not need to use a string t figure out what is on the stage. if(contains(bild1Loader)){...} would trace true it bild1loader is a child.
While the music played you worked by candlelight
Those san francisco nights
You were the best in town
Just by chance you crossed the diamond with the pearl
You turned it on the world
That’s when you turned the world around
-
 Originally Posted by Kid Charlie
i don't see anything wrong in your code on a quick glance. Are you getting an error? You might not need to use a string t figure out what is on the stage. if(contains(bild1Loader)){...} would trace true it bild1loader is a child.
Hi!
Yeah, I got it to work your way using contains, which is great! But I would still like to know what's wrong with my text variable thingie (since I would like to use similar stuff in the future on stuff where contains isn't applicable)...
When I export the movie with my string variables I get these compile messages:
Code:
Line 56 Warning: 3596: Duplicate variable definition. var lastChange:String = "bild3child";
Kube 62 Warning 3596: Duplicate variable definition. var lastChange:String = "bild1child";
It changes image one time, and then I get this error:
Code:
ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
at flash.display::DisplayObjectContainer/removeChild()
at banner_fla::MainTimeline/changeBild()
at flash.utils::Timer/flash.utils:Timer::_timerDispatch()
at flash.utils::Timer/flash.utils:Timer::tick()
-
Gotcha. When you declare var lastChange:String = "bild2child"; you are creating a new variable. Flash thinks you have 2 variables that are the same. instead just lastChange = "bild2child"; would work. lastChange is already defined as a string variable.
The second error wouldn't happen with the contains code. What is happening is that the loader isn't done loading when your code executes. So the loader isn't done and the bild1Loader isn't a child. You can use an event listener to figure out when something is fully loaded: bild1Loader.addEventListener(COMPLETE, completedFunction);
While the music played you worked by candlelight
Those san francisco nights
You were the best in town
Just by chance you crossed the diamond with the pearl
You turned it on the world
That’s when you turned the world around
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|