-
progress bar
i tried to make a progress bar for this so that everything would be loaded before it starts, i searched and found somone who showed me, but it didnt work. how can i make this work? the code is this
Code:
package
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.controls.ProgressBar;
import flash.controls.ProgressBarMode;
public class gaia extends Sprite
{
private var pb:ProgressBar = new ProgressBar();
private var leaf:Loader;
private var instructions:TextField = new TextField();
public function gaia ()
{
pb.width = 150;
pb.mode = ProgressBarMode.POLLED;
pb.source = Loader;
pb.move(20,20);
instructions.text = "use the arrow keys to move around";
instructions.y = 10;
instructions.x = 20;
instructions.width = 500;
leaf = new Loader;
leaf.load (new URLRequest("http://a2.cdn.gaiaonline.com/gaia/members/ava/04/41/207d91bd6d4104_flip.png"));
leaf.x = 20;
leaf.y = 20;
addChild (pb);
addChild (instructions);
addChild (leaf);
stage.addEventListener (KeyboardEvent.KEY_DOWN,keyPressedDown);
}
private function keyPressedDown (event:KeyboardEvent):void
{
var x_speed:int=0;
var y_speed:int=0;
switch (event.keyCode)
{
case Keyboard.LEFT :
leaf.load (new URLRequest("http://a2.cdn.gaiaonline.com/gaia/members/ava/04/41/207d91bd6d4104.png"));
x_speed = -2;
break;
case Keyboard.RIGHT :
leaf.load (new URLRequest("http://a2.cdn.gaiaonline.com/gaia/members/ava/04/41/207d91bd6d4104_flip.png"));
x_speed = 2;
break;
case Keyboard.UP :
y_speed = -2;
break;
case Keyboard.DOWN :
y_speed = 2;
break;
}
leaf.x += x_speed;
leaf.y += y_speed;
}
}
}
and my terminal spit this out
Code:
ryland@ryland-desktop:~/Desktop/programming$ mxmlc gaia.as
Loading configuration file /usr/local/flex/frameworks/flex-config.xml
/home/ryland/Desktop/programming/gaia.as(16): col: 24 Error: Type was not found or was not a compile-time constant: ProgressBar.
private var pb:ProgressBar = new ProgressBar();
^
/home/ryland/Desktop/programming/gaia.as(16): col: 42 Error: Call to a possibly undefined method ProgressBar.
private var pb:ProgressBar = new ProgressBar();
^
/home/ryland/Desktop/programming/gaia.as(16): col: 42 Error: Call to a possibly undefined method ProgressBar.
private var pb:ProgressBar = new ProgressBar();
^
/home/ryland/Desktop/programming/gaia.as(22): col: 23 Error: Access of undefined property ProgressBarMode.
pb.mode = ProgressBarMode.POLLED;
^
/home/ryland/Desktop/programming/gaia.as(11): col: 27 Error: Definition flash.controls:ProgressBar could not be found.
import flash.controls.ProgressBar;
^
/home/ryland/Desktop/programming/gaia.as(12): col: 27 Error: Definition flash.controls:ProgressBarMode could not be found.
import flash.controls.ProgressBarMode;
^
ryland@ryland-desktop:~/Desktop/programming$
can anyone tell me how to make this work?
-
Hi, use another swf to load the swf that you want loaded(if that makes sense). Create a completely new flash file with the same dimensions and settings as the one you want loaded. Then add
Code:
var req:URLRequest = new URLRequest("my_flash_file.swf");
var myLoader:Loader = new Loader();
myLoader.load(req);
myLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, checkProgress);
function checkProgress(p:ProgressEvent):void {
var percent:int = (p.currentTarget.bytesLoaded / p.currentTarget.bytesTotal) * 100;
bar.width = percent * 2;
}
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event):void {
bar.visible = false;
addChild(myLoader);
}
You will need to add a bar movieclip to the stage and name the instance "bar".
Hope this makes sense, I havent had much sleep so my head is a bit cloudy.
n
-
looks good to me! thanks, ill try it out when i have the time
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
|