q1)where do i set screen dimensions?
q2)how can i set the images position on screen without using the imageLoaded function because I need to display many images and dont want to create this imageLoaded for every image.
package
{
import flash.display.Sprite;
public class atest1 extends Sprite
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
public function atest1()
{
var loader:Loader = new Loader;
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
loader.load(new URLRequest("ladybug.png"));
//loader.x=200;
//loader.y=100;
}
private function imageLoaded(event:Event):void
{
var image:Bitmap = new Bitmap(event.target.content.bitmapData);
addChild(image);
//image.x=200;
//image.y=10;
}
}
}
var li:atest1= new atest1 ()
here is an example (with just one loop):
var array:Array=["url1","url2","url3"]; // u should fill that array somehow with more data...
var wid:Number=150;
var hei:Number=100;
var x_counter:int=0;
var y_counter:int=0;
var columns:int=4;
function loaderFunc():void{
for (var i:Number = 0; i < array.length; i++){
var thumb_url = array[i].toString();
var thumb_loader = new Loader();
thumb_loader.load(new URLRequest(thumb_url));
thumb_loader.x = (wid+10)*x_counter;
thumb_loader.y = (hei+10)*y_counter;
addChild(thumb_loader);
if (x_counter+1 < columns){
x_counter++;
} else {
x_counter = 0;
y_counter++;
}
}
}
An easier way is using paramters in the constructors but it doesnt work??
why does this code fail to load anything without an error?
package
{
import flash.display.Sprite;
public class atest1 extends Sprite {
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.text.*;
private var myy:int;
private var myx:int;
private var txt1:TextField = new TextField();
public function atest1(x:int,y:int) {
var loader:Loader = new Loader; myx=x; myy=y; loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); loader.load(
new URLRequest("ladybug.png")); txt1.text =
"Text1"; addChild(txt1);
import flash.text.*; }
private function imageLoaded(event:Event):void {
var image:Bitmap = new Bitmap(event.target.content.bitmapData); image.x=myx; image.y=myy; addChild(image); } } }
var
li:atest1= new atest1(10,200); //doesnt work
Scene 1, Layer 'Layer 1', Frame 1, Line 1 1198: Attributes are not allowed on package definition.
Scene 1, Layer 'Layer 1', Frame 1, Line 2 1084: Syntax error: expecting identifier before mult.
Scene 1, Layer 'Layer 1', Frame 1, Line 4 1037: Packages cannot be nested.
Scene 1, Layer 'Layer 1', Frame 1, Line 6 1084: Syntax error: expecting identifier before mult.
Scene 1, Layer 'Layer 1', Frame 1, Line 9 1071: Syntax error: expected a definition keyword (such as function) after attribute *, not public.
Scene 1, Layer 'Layer 1', Frame 1, Line 9 1084: Syntax error: expecting rightbrace before leftbrace.
Scene 1, Layer 'Layer 1', Frame 1, Line 50 1071: Syntax error: expected a definition keyword (such as function) after attribute *, not private.
no it doesnt work.
Here is my whole code and I get1 error with addchild
package { [ SWF(backgroundColor="blue", width="400",height="300")] import flash.display.Sprite; public class atest1 extends Sprite { [ SWF(backgroundColor="0x00ff00", width="400",height="300")] import flash.display.Bitmap; import flash.display.Loader; import flash.display.Sprite; import flash.events.Event; import flash.net.URLRequest; import flash.text.*; private var myy:int; private var myx:int; private var txt1:TextField = new TextField(); private var img1:String; public function atest1(myimage:String) { var loader:Loader = new Loader; img1=myimage; myx=100; myy=100; loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); loader.load( new URLRequest(img1)); } private function imageLoaded(event:Event):void { var image:Bitmap = new Bitmap(event.target.content.bitmapData); image.x=myx; image.y=myy; addChild(image); } } }
var li:atest1= new atest1("ladybug.png");
var addChild(li);
Hi,
no no that is not the file that is old code and I get an error with addchild in flashbuilder
What I wanted to do is pass the string of the image to display
package
var li:as2= new as2("explorer.png");
North America
Europe, Middle East and Africa
Asia Pacific