ActionScript 3.0 :: Sprite Loader From Library Onto The Stage?
Jan 30, 2009
Loading a Sprite or MovieClip from the library to the Stage is simple. You just export the symbol and do the following code:
var mySp:Sprite1 = new Sprite1();
addChild(mySp)
assuming the exported sprite is called "Sprite1" and the base class is flash.display.Sprite
But what if you have many sprites and want to encapsulate this into a function with the sprite name passed as a string? What would the code in the function look like? Somehow you have to cast the string as the name of the sprite class defined in your export but I'm not sure how. I've seen a sample using the "as" keyword but try searching "as" in the help you you don't get much help.
Code:
function loadSpriteFromLibrary(sSpriteName:String)
{
//load the sprite with an exported name passed into sSpriteName onto the stage
//what would the code look like?
}
View 2 Replies
Similar Posts:
Dec 21, 2011
I want to get my star to use one of the loaded sprites, I manage to find the correct urlLoader in my loader, but are unsure what I should return to give it the sprite.[code]...
View 2 Replies
Jun 29, 2011
Do you know why this AS3 code works:
var loader = new Loader();
loader.load(new URLRequest("http://127.0.0.1/items/boing.png")));
var o:DisplayObject = addChild(loader);
o.x = 100;
o.y = 100;
But if I cast to sprite it doesn't work? Ie the sprite appears on (0, 0) instead of (100, 100):
var loader = new Loader();
loader.load(new URLRequest("http://127.0.0.1/items/boing.png"))
var o:Sprite = Sprite(addChild(loader));
o.x = 100;
o.y = 100;
How would I properly have a sprite instead of a DisplayObject? I need some sprite's features (drag'n drop, useHandCursor...), yet I wish I could still use the very quick writing with the loader.
View 2 Replies
Sep 18, 2009
In AS3 / CS4 I'm trying to programmatically create a bunch of rectangular objects, let's call them 'cards', that will contain an image and a colored background and eventually some other elements like text. I want to create alot of these cards and move them around inside of a larger panel (also a Sprite) of sorts. I can successfully create colored rectangles in my cards and place the cards where I want in the panel, but whenever I try to add an image to a card, I can't seem to position the image inside the card's coordinate space, it ends up being placed inside the larger panel's coordinate space instead, even though I'm adding the image/loader as a child of the card. I thought maybe it had something to do with having to wait until the image loading was complete, so I added the listener as a test but that didn't work. Here's the code:
[Code]...
View 1 Replies
Feb 3, 2009
I've got a few spites on stage that are created dynamically and live in an array. I'm rotating images through these sprites and now need to know which image is in a sprite when clicked. My code: loading the images:
[Code]...
View 1 Replies
Feb 25, 2010
I want to load an external image (dest) and display it on the stage, and i want to load another image (src) which will not be visible. When i hold the left mouse button on the image that appears on the stage, then a function that start copies the src image to the dest will be invoked. Actually i want to reproduce the scratch effect on an image that hides another underneath. here is my code [ the copypixels function is triggered on mouse_move event for debug purposes ]
package
{
import flash.display.Sprite;
import flash.display.BitmapData;
[Code]....
Although the two images are loaded into memory and the first one is shown on the stage, when the mouse_move events triggers the corresponding handlers the copy does not work.
View 1 Replies
Jan 2, 2011
I have a swf that I load into another swf and add to a Sprite from the library. The Sprite is enabled for drag/drop so I can move the loaded swf and that part works fine . On the imported swf is a scrollbar it no longer works. I
[Code]...
View 9 Replies
Jul 27, 2010
I'm loading some external assets with the Loader class. I've done this a lot over the years, but seem to be coming across a problem I haven't had before. I want to display two instances on the stage at the same time of a .png I'm loading externally. If I use the Loader instance's contentLoaderInfo.content object in more than one sprite, the bitmap just "moves" from the first instantiated sprite to the second. I've tried duplicating the sprite with Senocular's duplicateDisplayObject class, but for some reason, it's not working right. But shouldn't I be able to use multiple instances of an imported bitmap like this just as if it were in the library of the .fla? If so, what do I need to do?
View 3 Replies
Apr 4, 2009
I would like to be able to make changes to a colour gradient of a sprite from my library, as opposed to one drawn dynamically. So the code I thought would look something like this:
Code:
var radType:String = GradientType.RADIAL;
var radMatrix:Matrix = new Matrix();
radMatrix.createGradientBox(120,120);
var radColours:Array = [0x3174d0, 0x15396f];
var radAlphas:Array = [1, 1];
var radRatios:Array = [0, 255];
var myLibrarySprite:spriteInLibrary = new spriteInLibrary();
myLibrarySprite.graphics.beginGradientFill(radType, radColours, radAlphas, radRatios,radMatrix);
addChild(myLibrarySprite);
I've been using essentially this code (plus a bit for say drawing a square) happily to gradient fill sprites that are dynamically drawn. I don't get any errors from this.
I have tried adding myLibrarySprite.graphics.clear() but that does not make a difference.
View 3 Replies
Nov 30, 2010
I have set up a functioning xml image gallery with simple left and right arrows. I am now trying to make it an infinite looping gallery swapping the first and last sprites in an array and + and - their x value so they "physically" move in the photos container.
All of this works fine except for the actual loaded image. The xml data, name description, and image to be loaded are set up in one function and all the data is added to the sPhotoSprite (sprite) in this function. This All works perfectly..
A second function is then called to add the current image:
var currentImage:Loader = Loader(evt.target.loader);
then currentSprite.addChild(currentImage); (the sprite is declared at the start)
The problem being that the sPhotosSprite is no longer reference-able. I've tried :
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, function( evt:Event)
{ imageLoaded( evt, sPhotosSprite )
} );
But this only ever returns the final sprite. The same problem of only ever returning the final sprite occurs when I try setting an external sprite to hold the current sprite in it and then referencing it in the second function.
View 1 Replies
Jun 30, 2011
I am trying to create a newspaper that consists of four pages. Each page i have created and are sitting in the library as sprites. Each page has buttons that need linking so that when pressed it loads the next page or page that i want. This is the part i am confused with =/ how do i make the buttons on each page load the next page (sprite) from the library? Basically i want to no how to make a button load a sprite from the library when clicked. Does anyone no the script for this?
View 5 Replies
Mar 6, 2012
In Flash I am able to create a font asset and add it to the library:I want to convert this asset into some BitmapData that will contain all of the characters with the correct letter spacing/line height etc.
Is there an inbuilt way of doing this other than manually creating text fields, adding a character, using BitmapData.draw() and then adding the result to a sprite sheet?
If I need to do it manually like above, is there a way to retrieve all of the embedded characters? For example, in the above screenshot I'd expect only a-z, A-Z. Or will I need to note these manually as well?
View 1 Replies
Aug 12, 2009
im working on an image viewer and im loading an image to a loader and then add the loader to the stage.I want the user to be able to drag and drop the image but since it's a loader i dont know how to do it.
I tried
imageLoader.startDrag = true;
imageLoader.content.startDrag = true;
but im getting an error on both.
View 2 Replies
Nov 14, 2011
Im currently in need of a library that contains flash.display.loader. I searched in google but the libraries I found doesn't contain display.loader. Would you mind to give me link where I can download this?
View 1 Replies
Nov 27, 2010
Can we load image or any asset from Library using LOADER in action script 3.0
View 4 Replies
Sep 17, 2009
I just want to ask if is it possible to load a movieclip from the library using the Loader class together with the URLRequest and then use gotoAndPlay method?
View 1 Replies
Mar 10, 2012
I need to load (dynamically) an image stored in the library of Adobe Flash to the loader component. So far, i have imported this image to the library and exported it to ActionScript under the linkage section. I have named its identifier as well.
I am using ActionScript 2.0.
View 1 Replies
Mar 10, 2012
I need to load (dynamically) an image stored in the library of Adobe Flash to the loader component. So far, i have imported this image to the library and exported it to ActionScript under the linkage section.
View 3 Replies
Mar 21, 2011
i've been using different loaders in the past, here are the most popular:.
[Code]...
which one is the best one and for which challenges?
View 1 Replies
Dec 15, 2009
I'm using Flex builder 3 for my main application (web-based), and I need to load multiple swf files built in flash cs4 (AS3) at different times. The flash swfs import assets from a separate flash swf used as a shared library. I'm using 1 swf loader in flex to keep 1 flash swf loaded at a time.Loading the first swf works fine, but loading subsequent swfs generates an error in importing from the shared library swf.
Here's an example of an error:
"ReferenceError: Error #1065: Variable sharedApps is not defined."
View 3 Replies
Aug 27, 2011
I'm sure you're expecting me to have forgotten to use addChild. I wish it was that easy. I will say I'm very new to AS3.0. I have a movie clip in my library that contains a small PNG file and a text label. The linkage properties are: Class: shapes.HorizontalIcon, Base class: flash.display.Sprite.[code]As far as I can tell this should work. There are no errors. The trace statement above shows up in the output. The parent sprite is also an item from the library. It shows up on the stage. I tried adding a random TextField to the parent sprite it showed up on the stage just fine.Something isn't working right, but I don't know where to start debugging this.
View 7 Replies
Nov 15, 2010
ActionScript Code:
var MapBtnArray:Array = [];
var MapBtnSprite:Sprite;
var i:int;
[Code].....
I'm using to code above to create several sprite on the stage, but when I click on the sprite, the index of each trace work just fine (output of J is according to the target i click); however MapBtnArray[j].x keep equals to "0"
I want the coordinate of the sprite on stage, how come what i get is "0" instead?
View 1 Replies
Jul 8, 2009
I try to align center a sprite container in the center of the stage.
What can be the method to do it?[code]...
View 5 Replies
Sep 2, 2010
I have a Flash website that I have tested in various browsers on my laptop, and it looks fine. I tested it on another PC in Firefox 3.6.8 (same version as my laptop) but for some reason, there is a sprite missing from the stage. On the same PC, the website looks fine in IE8. The vanishing sprite aside, the whole site is kind of sluggish in Firefox. The PC is kind of slow and old, but I can't see why that would cause images to vanish.
View 1 Replies
Oct 29, 2011
I'm making an action game and I'd like to know what should be the maximum size of the stage (mine is 660 x 500).Also I'd like to know how big a game-sprite should be. Currently my biggest sprites have a size of 128 x 128 and I read somewhere on the internet that you should not make it bigger because of performance issues.
If you want to make e.g. big explosions with shockwaves even 128 x 128 does not look very big. What's the maximum size I can definitely use for sprites?
View 2 Replies
Nov 30, 2011
I'm trying to get a simple AS3 app up and running, and for some reason, I cannot get a sprite to show. At this point, all I want to do is get a red sprite to fill the stage.
public class Main extends Sprite
{
public function Main():void
[code].....
View 2 Replies
Oct 29, 2011
I'm making an action game and I'd like to know what should be the maximum size of the stage (mine is 660 x 500). Also I'd like to know how big a game-sprite should be. Currently my biggest sprites have a size of 128 x 128 and I read somewhere on the internet that you should not make it bigger because of performance issues. If you want to make e.g. big explosions with shockwaves even 128 x 128 does not look very big. What's the maximum size I can definitely use for sprites?
View 4 Replies
Jul 16, 2009
I thought would be coded like this:
var sp:Sprite = new Sprite();
sp.graphics.beginFill(0xFF88CC);
sp.graphics.drawCircle(0, 0, 50);
[Code].....
however, I realize even tho im looping that addChild method, its still adding sp, so do I add a new naming convention in the loop, or should I be adding these instances to another display object.... this seems like such a simple thing to do yet I cant figure it out, I also want to randomize the x and y, but this first seems to be the issue I need to address.
View 1 Replies
Nov 15, 2010
PHP Code:
var MapBtnArray:Array = [];
var MapBtnSprite:Sprite;
var i:int;[code].....
I'm using to code above to create several sprite on the stage, but when I click on the sprite, the index of each trace work just fine (output of J is according to the target i click); however MapBtnArray[j].x keep equals to "0".I want the coordinate of the sprite on stage, how come what i get is "0" instead?
View 3 Replies
Aug 6, 2010
I am creating an AIR nativeWindow. I am adding two children, an HTMLLoader and a Sprite. The child Sprite has two children, a TextField and a Sprite that will be used to draw. I have set stage.scaleMode = "noScale" and stage.align = "TL", which the HTMLLoader seems to respect. However, the child Sprite scales its children whenever I set a height.
public function BaseWindow(){
var winInit:NativeWindowInitOptions = new NativeWindowInitOptions();
winInit.type = NativeWindowType.NORMAL;[code]..........
How do I prevent the distractor Sprite from scaling its children?
View 1 Replies