Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Library Item Exists?



If there a way in flash to see of a linked object exists?  For example, I have in my library a Bitmap with the identifier "ico_UNK_48" (no quotes).  How can I discover in ActionScript if the Bitmap exists before I attempt to load it?

---------------------------------------
TINSTAAFL, which is why I contribute.



Tek-Tips > Adobe(Macromedia): Flash Forum
Posted on: 3 Nov 06 17:40


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

If File Exists, Load It, Else Insert Library Item
I've googled around for a while tonight for things like "actionscript 1 check file exists" and so on, and the best I find is people saying to check if a file exists, do this
CODEfileExists=new LoadVars();
fileExits._parent=this;
fileExists.onLoad=function(success)
{
//success is true if the file exists, false if it doesnt
if(success)
{
//the file exists
var nm=this._parent.createEmptyMovieClip("swfHolder",1); //so create a movieclip
nm.loadMovie("myfile.swf"); //and load our .swf file into it
}
}
fileExists.load("myfile.swf") //initiate the test

Preloading An Mp3 That Exists Only In The Library
Situation - I have 2 files, preload.fla and main.fla.
Preload.fla's library has an music.mp3 that is exported for actionscript. Scene 1 of preload.swf has a preloader and Scene 2 dynamically loads main.swf. (Main.fla contains the sound object defined and starts the music). ( i have other music depending on what section you are in and that's why i defined it there)

Problem - The preloader (scene 1 of preload.fla) is preloading the music before even my preloader shows up, which defeats the whole purpose of my preloader. Whereever i put this music it's the same thing. I tried loading main.swf on another level and it still does it since it was suggested that keeping the preloader and everyything else on separate levels should work.

Question - Is this the best way to do it cos i've tried many versions that just don't seem to work? How can i get my preloader to recognise the music.mp3 in it's library?

Loading A Movie That Exists In The Library
Hi

Does anyone know if you can load an existing movieclip
directly from your library into the current scene without placing an instance of that movieclip in the scene and jumping to that?

Or to load a movieclip must you always have an instance of it in the scene to jump to it?

I appreciate your help
thankkkkkkk u

torcha

Checking If A Symbol Exists In The Library
Hi

My situation is thus: I have an XML file with entries, each of which contains a handle (linkage ID) to the movie clip that represents that entry onstage.

So I dynamically load these symbols in from the library accordingly. Only problem is, I need to be able to count how many of those entries are valid, that is, how many of the XML entries have handles that actually do correctly correspond to the names of the symbols in the library.

So right now in order to count the entries I am using the value of how many entries were in the XML file but this is wrong, I need a value of how many entries in the XML correspond correctly to a library symbol.

As it stands now, if all the names in the XML file match those in the .fla, all is good. Otherwise, issues. The thing is, I want this setup to be robust so the program takes responsibility and resolves issues if there are errors in the XML.

Now, the only way I can see to fixing this simply, is if there is a way to check if a symbol exists in the library -- without actually trying to load it.

That way I can count just those symbols from the XML file that also do exist in the library.

TIA,

-Nick

[F8] Use Code To Detect If Library Symbol Exists?
My question: Is there a way to use ActionScript to explicitly detect if a particular symbol exists in the library?

My situation: I have an XML file with entries, each of which contains a handle (linkage ID) to the movie clip that represents that entry onstage.

So I dynamically load these symbols in from the library accordingly. Only problem is, I need to be able to count how many of those entries are valid, that is, how many of the XML entries have handles that actually do correctly correspond to the names of the symbols in the library.

So right now in order to count the entries I am using the value of how many entries were in the XML file but this is wrong, I need a value of how many entries in the XML correspond correctly to a library symbol.

As it stands now, if all the names in the XML file match those in the .fla, all is good. Otherwise, issues. The thing is, I want this setup to be robust so the program takes responsibility and resolves issues if there are errors in the XML.

Now, the only way I can see to fixing this simply, is if there is a way to check if a symbol exists in the library -- without actually trying to load it.

That way I can count just those symbols from the XML file that also do exist in the library.

Library Item ?
Hello everyone,

I am currently working on a project that contains a significant amount of library items(around 700). Does anyone know if this will affect the performance of the movie?

Thanks in advance!


SunsFan13
duvalldesigns.com

Library Item In New Window
Hello all,

I am trying to open a new window to display a library item (graphic or movie clip.)

I hope to do this without using a getURL that points to an external .html file.

I've tried a loadMovie command where URL: _root.mygraphicname

and no luck.

Any thoughts?

Thanks-
Steve

Cloning A Library Item
I am going crazy over this, I'm new to flash and am using 2004 Pro.


How do I copy a Movie clip in the library without having it tied to the clip I copied it from?

ie. Create a simple clip call it clip1 and then duplicate it and call it clip2. I now have two separate clips in the library. They should be separate and distinct right? Now edit clip1 and change the color of an existing shape in the clip... say the color: red to green. When I look at clip2, the same shape has changed colors! I really don't want to have to make eachclip from scratch when they are complex and similar. How can I copy and item in the library and then place it as new distict item, not just an instance that will change evertime I edit the original I copied it from

any help from the rest of you would be greatly appreciated. I'm converting from swish to flash and find flash 100% frustrating and dificult, just hopin the switch will eventually pay off.

thanks!

Jeremy

Loadmovie On A Library Item
Hi,

If I set a library movie clip linkage to 'Export for Actionscript' (and say for example, named it mcContent), then in my timeline issue this command:

mcContent.loadMovie("blah.swf");

it doesn't work. I would have expected it to load the movie clip into the mcContent symbol.

Can anyone explain if this is possible or not and why?

I would like to perform some silent preloading while other things are happening.

Thanks

Loading Library Item
Hello folks! I have a situation that I need three graphics or movies from the library loaded into a movieClip that is on the stage.

When I click a button, I want to load "gfx_red" (which is a red circle graphic) into the movieClip called "colourHolder".

I've used this code, but it doesn't seem to do the trick:

on (release) {
attachMovie("colourHolder", "gfx_red");
}

What am I doing wrong? Oh BTW, when I made the graphics and movieClip I already "export as ActionScript" from the linkage menu.

Glenn

Library Item Conflict
Hi. I'd appreciate any help people can offer regarding this problem. I am creating some animations using Flash 8. Some work just fine. Others give me the following message when I try to add a new movie clip: One or more library items exists in document. It gives the choice to replace or not replace the items. Both choice are bad. If I replace the items, one of the original animations gets messed up. If I don't replace, the new animation gets messed up. I'm unclear about which items are overlapping. The problems don't seem to make sense. For example, if I say "don't replace" my new animation will suddenly have additional moving parts that were not part of the original.

Any ideas for solutions or workarounds?

Thanks.

Corrupt Library Item
How can I delete a library item without selecting it in the list. It is a .png file, and when I select it, the app crashes, so I'd rather not leave it in the library, and wish to replace it. Help...! belongs to MX 2004 pro fla file.

Why Would You Add A Library Font Item?
I'm just confused what a font item in the library would be for? Is it just like adding a dynamic textfield and embedding all the characters there??

Import Movie As A Library Item?
This may sound like a silly question, but how can I import a movie as a library item for another movie?

Help : How To Load Another Swf File And Use The Library Item Of It
I have two flash files

one is main.swf , another is library.swf
in the library.swf file , there is a movieClip which have choice the export for use and have already fill the exported URL field in "main.swf" and the ID is call EXT_TEST_MC, so that main.swf can call the library item of library.swf for use, it works fine if i use flash player 7 and AS 2 to complie, but if i use flash player 6 and AS 2 to complie , it doesn't work.

The script is as below,


Code:
#frame 1
myLoader = new MovieClipLoader();
myListener = new Object();
myListener.onLoadStart = function (target_mc) {}
myListener.onLoadProgress = function (target_mc, loadedBytes, totalBytes) {}
myListener.onLoadComplete = function (target_mc) {}
myListener.onLoadInit = function (target_mc)
{
_root.attachMovie("EXT_TEST_MC", "test", 10, {_x:0, _y:0});
}
myListener.onLoadError = function (target_mc, errorCode)
{}
myLoader.addListener(myListener);
myLoader.loadClip('library.swf', "_root");



The above code work fine in flash player 7 + AS 2,
but I need it also work fine in flash player 6 + AS 2,
then I try to change the above code as below



Code:
#frame 1
loadMovie('library.swf', 10);
....
....
....
#frame 10 // already make sure the ext. swf has loaded in it
_root.attachMovie("EXT_TEST_MC", "test", 10, {_x:0, _y:0});


but it doesn't work, it can't attachmovie from the ext. swf's library.

So , anyone can help me to solve the problem

Thanks,
Jack.

A Script To Make An Mc For Every Library Item?
I'm currently working on a flash file to put on cd. The problem is the intro component to this piece requires the loading of roughly 1000 scaled down thumbnails. Hence rather than get flash to load each thumbnail as it needs them off the cd (and pause the piece for half a second or so), I want to import directly into the main fla, or a secondary one I'll load in, scaled down versions of the images.

I can file->import to library the 1000 images, that's fine. My question then is, how can I make a new movieclip, place an image in it, add a linkage name... automatically, for all these items? I've heard there is a type of scripting available within flash for this, any helpers on the matter?

thanks guys

[CS3] Dynamic Text In A Library Item
If anyone could help me with this problem I'd really appreciate it.

In my library I have a Movie Clip called OneFrameTile.

As the name suggests, it has only one frame, and in that frame I have a dynamic text field called letter.

The constructor of my main class creates an instance of my OneFrameTile class and chooses a letter of the alphabet. The text property of the dynamic text field is set to the chosen letter of the alphabet.

That all works fine, no problem.

But then I have another Movie Clip in my library, called TwoFrameTile.

It has two frames, and the dynamic text field (still called 'letter') is on the second frame.

When I ask the constructor in my main class to create an instance of TwoFrameTile, and assign a letter of the alphabet to the text property of my dynamic text field, I get an error message saying Cannot access a property or method of a null object reference.

In this case, when I debug the movie, the letter property of my TwoFrameTile instance is shown as null.

If anyone can tell me what I'm doing wrong, I'd be grateful.

Thanks for reading this.

DD

Dynamic Load Of Library Item
Hi Guys,
I know and love how to add a library item to the display object on the stage.

exacmple, I have a library item named libraryClip in the library.

var newLibraryClip:Sprite = new libraryClip();
addChild(newLibraryClip);

What I am trying to do is load a library item from a dynamic variable passed in through an xml file.

Somehow I need to pass the value of a variable to call on in the library

example...
//loading in xml
//xml now loaded
//variable passed on

var newLibraryClip:Sprite = new [dynamicVariable]();
addChild(newLibraryClip);


Does that make sense?

Clean Up Library After Item Removal
Hi everyone:


I tried to experiment with the Flash components and added a Button to the library and later discovered that the resulting size of the SWF became 700K (before it was around 60K). Now I removed the button from the stage and from the library and even though the size of SWF has shrunk down to 600K, it's still 10x larger than it was originally. Can someone suggest how to clean up my project and return to the original size of the SWF file?

AttachMovie Adds Library Item Twice?
Hi everyone!

I've come across this problem for the second time now, and I'm still not sure what solved it the first time.

I have a timeline that contains the clip "contentMC". On the same timeline the following AS appears:

_root.contentMC.attachMovie("home", "contentHolder", _root.contentMC.getNextHighestDepth());

The library item "home" contains several text objects. The strange thing is that, while the item is added as "contentHolder", the contents of "home" is also added to "contentMC". So when I use List Objects during preview, I get:

Level #0: Frame=24 Label="Interface Build"
Movie Clip: Frame=1 Target="_level0.contentMC"
Shape:
Text:
Text:
Text:
Text:
Text:
Text:
Text:
Text:
Movie Clip: Frame=1 Target="_level0.contentMC.contentHolder"
Shape:
Text:
Text:
Text:
Text:
Text:
Text:
Text:
Text:

The first row of "Text:" shouldn't be there.

I came across this problem before at a different level. That one was solved (I think) by replacing .getNextHighestDepth() with 1. This time, however, that doesn't help.
Anyone any ideas?

I've uploaded the .fla at: http://www.eurovoice.nl/flash/eurovoice01.fla

Thanks in advance!

Yours,
Andra

AttachMovie Adds Library Item Twice?
Hi everyone!

I've come across this problem for the second time now, and I'm still not sure what solved it the first time.

I have a timeline that contains the clip "contentMC". On the same timeline the following AS appears:
_root.contentMC.attachMovie("home", "contentHolder", _root.contentMC.getNextHighestDepth());The library item "home" contains several text objects. The strange thing is that, while the item is added as "contentHolder", the contents of "home" is also added to "contentMC". So when I use List Objects during preview, I get:
Level #0: Frame=24 Label="Interface Build"Movie Clip: Frame=1 Target="_level0.contentMC"Shape:
Text:
Text:
Text:
Text:
Text:
Text:
Text:
Text:
Movie Clip: Frame=1 Target="_level0.contentMC.contentHolder"Shape:
Text:
Text:
Text:
Text:
Text:
Text:
Text:
Text:The first row of "Text:" shouldn't be there.

I came across this problem before at a different level. That one was solved (I think) by replacing .getNextHighestDepth() with 1. This time, however, that doesn't help.
Anyone any ideas?

I've uploaded the .fla at: http://www.eurovoice.nl/flash/eurovoice01.fla

Thanks in advance!

Yours,
Andra

[CS3] RemoveMovieClip Not Working For One Particular Library Item
Hi there,

I built a website for our company, but because my boss kept adding stuff as I was building, the navigation-function became a total mess. On top of that, the need has risen to make the site multi-lingual, and I would like to get the back-button and deep-linking to work properly.

So, I decided to rewrite the navigation-function using the exanimo stateManager. The site structure basically has two levels: Six main sections (L1), most of which have subsections (L2). All these "pages" are library items that get attached to a holder MC (L0). So for instance, the first page is built by attaching "home_NL" to L0 and calling it L1, and then attaching "home_welkom_NL" to L1 and calling it L2.

This all works fine, until I've clicked “Voices”. If I click a section after that, the L0 gets faded out, but L1 is not removed. And since the function then tries to attach a new library item as L1 and will not continue until it is loaded, navigation simply hangs.

Unfortunately “luister_NL”, which is loaded when you click “Voices”, is a fairly complex movie clip (by my standards, at least). It allows the visitor to listen to samples of our voice-talents based on language, style and gender. These can also be selected and “ordered” through a form.
Something in this movie clip is preventing Flash from removing it from the stage, but I can’t figure out what.

I’ve uploaded the fla so you can check it out if you want.

Any suggestions on what could be causing this behaviour would be very welcome.
Thanks in advance!

Yours,
Andra

Attach A Library Item To The Stage With AS2
Hey all,

Long time since i've done this and i'm a little rusty.
How do I attach a library item to the Stage using AS2??


ActionScript Code:
Stage.attachMovie("myLogo", "myLogo", 1);


Does not seem to work??

Thanks in advance!
George

Loading A Library Item Dynamically
Hello,

I hope someone can help me with this as it's sending me nuts, I realise I'm probably missing the obvious, but I have tried looking through the help in Flash and all the forums, but I'm still not getting it.

The code:

function row12_MOUSEUP (event:MouseEvent):void
{
var chosenAbbr = event.currentTarget.name.toString();
var chosenAbb:Object = MovieClip(root).abbrArray[chosenAbbr];// traces instance names ok
trace ("from array" + chosenAbbr + " " + chosenAbb);
var tempClip:MovieClip = new chosenAbb();
trace (tempClip);
tempClip.x = 0;
tempClip.y = 0;
MovieClip(parent).chosenAbb1.addChild (tempClip);
}


To explain, when the mouse event occurs the current target gets a value from an array, this returns as a string which is the same as the name of the item in the library (exported for AS). This string reads out correctly for example 'clip1', the above code work if I replace 'var tempClip:MovieClip = new chosenAbb();' with 'var tempClip:MovieClip = new clip1();'.

I need the 'clip1' reference to be taken from the value supplied by the array, as a String it reads correctly but the value is not used to create the child, do I need to change the whole way of working? I've tried all sorts but am getting nowhere fast, any help/pointers would be greatly appreciated...

Many thanks

Pete

Creating Instance Of Random Library Item
I am trying to add 4 items to stage from the library, "Plane0", "Plane1"..."Plane3". Each uses a base class of "com.Plane", and an auto-generated class for itself (named "Plane0"..."Plane3").

com.Plane takes 4 parameters.

I use the following code to get the items on stage:


PHP Code:



// getDefinitionById is imported
for (var i:int = 0, i < 4, i++){
    var planeName:String =  "Plane" + i;
    var ClassReference:Class = getDefinitionByName(planeName) as Class;
    var myPlane:Plane = new ClassReference("param0","param1","param2","param3");
    addChild(myPlane);
}




but I get the following error:

ArgumentError: Error #1063: Argument count mismatch on Plane0$iinit(). Expected 0, got 4.

what am I missing here?

Attaching A Library Item To The Stage From A Class
First.. I want to make sure I'm following the best practice for what I want to do... I have a flash quiz that uses a class file and then on the last frame I want to attach a custom movieclip with logo graphics, etc on it and the score in it. I heard that best practice is not to have any graphics, etc. in the FLA file and try to keep it all in external class files. I put this movieclip in the library and set up linkage identifiers like so:


Code:
class = logo_mc
base class = flash.display.MovieClip
checked "export for actionscript"
checked "export in first frame"
How do I add this movieclip to the stage?? I see similar posts but people are not adding things to the stage with classes...

I tried a sample document like this:

Code:
package {

import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.*;

public class testing extends MovieClip {
private var logo_mc:MovieClip;

public function testing(){
loadMovieClips();
}
private function loadMovieClips(){
this.addChild(logo_mc);
}

}
}
But then I get this error:

Code:
TypeError: Error #2007: Parameter child must be non-null.
at flash.display::DisplayObjectContainer/addChild()
at testing/::loadMovieClips()
at testing$iinit()
What am I doing wrong? I'm coming from the actionscript 2 way of thinking where I would have several movie clips in the library that I would attach to the stage with attachMovie when needed.

Any help is much appreciated!

Library Item Drops Instance Names
Hi

I am using as3 and I have a SimpleButton in my library which I add via AS to my app.

The button is fairly simple with a 3 layers, text, hover and bg.
the text is a label which is across all the states with instance name = "btnLabel_txt" on a dynamic textField
the hover is a gfx which is across the last 3 states
and the bg is the initial gfx visible only on the first state.


When I run through the children of each of the button states they have all the correct objects in them but none of them have instance names (well ok they do but its the automatic ones not the ones I gave them)

What I have tried...
I have tried adding a single textfield for each state with different names but it didn't change the outcome.

My current clunky workaround...
I add a class that is the same as my Linkage name for the button
within it I determine which object the textfield is by using getQualifiedClassName I then set a ref to this textfield so I can change it using a simple setter


So what have I missed? Is there a way to keep the instance names?

or should I drop SimpleButtons and make my own via a MovieClip?

Thanks
T

Using Shared Library Item Seems To Lock Up .fla File.
hi guys,

i`m working with one master fla file and two child fla's.

the two child fla use library item that are linked to master fla file, and are updated every time .swf is published.
after working with the master .fla file, it becomes unable to save.

does anyone come across any similar problems? or know some solutions to this?

any help appreciated.

Convert Existing Library Item -> Drawing API?
Greetings, all -

I'd like to take an existing library graphic (vector, not bitmap) and "convert" it into a series of ActionScript commands which use the drawing API (beginFill, lineTo, etc.) to produce the same result. Is there any utility or export function that would facilitate this?

Or am I forced to try to convert the graphic into an svg file and then try to import that? I'm asking this because I like the idea of thoroughly encapulating the code for a preloader that uses my company logo. I'd love to have the whole thing, graphics and all, in an external AS file; nothing but text! For simple graphical elements that get reused, you wouldn't have to fish around for an external library item as well, or remember where that movie clip was...

Ed

Loading Library Item Into A Movie Clip?
How would I go about doing that?

Thanks,
Gerard

AS File Not Displaying Library Item On Stage
The following script works perfectly, but I can't get the library item (which is a mc, class "helmet") to display. Any ideas? Do I need to import additional classes to display the mc?


package {
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import fl.controls.listClasses.CellRenderer;
import fl.controls.ScrollBarDirection;

public class media extends MovieClip {

private var xmlLoader:URLLoader;


//the following function is what is not working at runtime//

public function loadbuttons():void {
var vidbut:MovieClip = new helmet();
vidbut.x=620;
vidbut.y =50;
addChild(vidbut);
}

public function media():void {

xmlLoader = new URLLoader ();
xmlLoader.load(new URLRequest("/playlist.xml"));
xmlLoader.addEventListener(Event.COMPLETE, getXMLdata);


}

public function getXMLdata(event:Event):void {
var campXML:XML = new XML(xmlLoader.data);
var vid:XML;
for each(vid in campXML.vid) {
campList.addItem({label:vid.attribute("desc").toXMLString(),
data:vid.attribute("src").toXMLString()});;
}

campList.selectedIndex = 0;
campList.addEventListener(Event.CHANGE, playnewvid);
FLVPlayer.source = campList.selectedItem.data;
FLVPlayer.pause();
campList.visible = false;

}


function playnewvid(event:Event):void {
FLVPlayer.play(event.target.selectedItem.data);
}





























Edited: 09/27/2008 at 09:31:33 AM by iRyFlash

AS 2 Using Shared Library Item Seems To Lock Up .fla File.
hi guys,

i`m working with one master fla file and two child fla's.

the two child fla use library item that are linked to master fla file, and are updated every time .swf is published.
after working with the master .fla file, it becomes unable to save.

does anyone come across any similar problems? or know some solutions to this?

any help appreciated.

Using Shared Library Item Seems To Lock Up .fla File.
hi guys,

i`m working with one master fla file and two child fla's.

the two child fla use library item that are linked to master fla file, and are updated every time .swf is published.
after working with the master .fla file, it becomes unable to save.

does anyone come across any similar problems? or know some solutions to this?

any help appreciated.

Find All Instances Of Library Item Currently Present On The Stage?
Hi,

well the question is in the topic - is that possible or not? And if yes, how? Answer, link, whatever, thanks.

Refer The Library Item Inside A Scrollpane Component
Hi

I'm using a scroll pane component to load a movieclip from library. Everything is working fine. But I want to refer that movie clip inside the compnent to add a zoom option for that. How can we refer that.

JSFL - Add An Item From The Library To A Specific Frame On The Timeline
Hi all,
Is possible to do what I am asking in the title using JSFL?

Thanks

Creating Multiple Instance Of Single Library Item
So I'm trying to bone up on my AS3, and I wana make a dart game or something like Space Invaders so I'm going step by step. What I have so far is a little ship that moves left and right via key press, when you hit the space bar it fires off a rocket and does a simple hit test on a big block.

What I'm wondering how to accomplish is when I hit the fire button I use addChild and it goes through the air, however I can't hit that fire button again to create a new addChild object, I'm wondering how you would create many rockets at once?

I know there is a better way to queue up keyDown events into an array but I haven't worked through that logic puzzle yet (please don't include that code I wana figure it out my self)

Here is the AS3 code I have so far, there are some extra variables in there for checking I plan on doing when I get to it.


Code:

package {

   import flash.display.MovieClip;
   import flash.display.Sprite;
   import flash.display.Stage;
   import flash.events.Event;
   import flash.events.MouseEvent;
   import flash.events.KeyboardEvent;

   public class asteroids extends MovieClip {

      public function asteroids() {

         var staWidth:int = 400;
         var staHeight:int = 400;
         var topBounds:int = 0;
         var leftBounds:int = 0;
         var bottomBounds:int = staHeight;
         var rightBounds:int = staWidth;
         var isRocketFire:Boolean = false;
         var hasHit:Boolean = false;
         var ship:MovieClip = new SpaceShip();
         var rocketFire:MovieClip = new rocket();
         var bigBlock:MovieClip = new block();


         addChild(ship);
         ship.x = 200;
         ship.y = 350;

         addChild(bigBlock);
         bigBlock.x = 200;
         bigBlock.y = 10;
         bigBlock.width = 400;
         bigBlock.height = 20;

         // Start of KeyDownHandler - Move rocket

         stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
         function keyDownHandler(event:KeyboardEvent):void {

            var LEFT:int = 37;
            var RIGHT:int = 39;
            var GO:int = 38;
            var currentKey:int = event.keyCode;

            // trace(event.keyCode);

            if (currentKey == LEFT) {
               ship.x -= 7;
            } else if (currentKey == RIGHT) {
               ship.x += 7;
            }
         }

         // End of keyDownHandler

         // Start of keyUphandler -- Rocket fire

         stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
         function keyUpHandler(event:KeyboardEvent):void {

            var FIRE:int = 32;
            var currentKey:int = event.keyCode;

            // trace(event.keyCode);

            if (currentKey == FIRE) {
               addChild(rocketFire);
               rocketFire.height = 10;
               rocketFire.x = ship.x;
               rocketFire.y = ship.y - 15;
               isRocketFire = true;
            }
         }

         // End of keyUpHandler

         stage.addEventListener(Event.ENTER_FRAME, moveRocket);
         function moveRocket():void {
            if (isRocketFire == true) {
               rocketFire.y = rocketFire.y - 10;
               stage.addEventListener(Event.ENTER_FRAME, hitTest);
            }
         }
         
         function hitTest():void {
            if (rocketFire.hitTestObject(bigBlock) && (isRocketFire == true)) {
               trace("boom");
               isRocketFire = false;
               stage.removeEventListener(Event.ENTER_FRAME, hitTest);
            }
         }
      }
   }
}

Thanks,
Steve

Casting XML Node Text Back Into A Library Item Class
Hello,

In my library I have a movieclip called START_GAME_BTN that uses the same name for its class which is START_GAME_BTN.

The problem I am having is figuring out how to cast the node text for <clipName> which is START_GAME_BTN back into the item in my library.

The XML snippet looks like this:


Code:
<startGameButton>
<clipName>START_GAME_BTN</clipName>
<position>
<xpos>560</xpos>
<ypos>420</ypos>
</position>
</startGameButton>
In my class that is parsing the XML needed to derive the items necessary for screen display, I initally do this for the start game button:


Code:
private var _startGameBtn:MovieClip;
But this is wrong because it really needs to be cast like this:


Code:
private var _startGameBtn:START_GAME_BTN;
Unfortunately this is where I am a little stumped. I tried doing this:


Code:
_startGameBtn = _xmlScreenData.screen.startGameButton.clipName as MovieClip;
But when I ran through the debugger the value of _startGameBtn was still null. I then tried this:


Code:
var gameButton:String;
gameButton = _xmlScreenData.screen.startGameButton.clipName;
_startGameBtn = gameButton as MovieClip
Unfortunately _startGameBtn was still null.

It's almost like I need to do:


Code:
//
_startGameBtn:_xmlScreenData.screen.startGameButton.clipName as _xmlScreenData.screen.startGameButton.clipName
_startGameBtn = new _xmlScreenData.screen.startGameButton.clipName()
//
But I know this won't work...has anyone run into this problem before?

Any suggestions would be greatly appreciated.

cheers,

frank grimes

How To Access Nested Movieclips Inside A Library Item, From A Class
Hey everyone,

I got this dilemma, i have a Sprite in the library linked to a class. Inside the sprite i have a MovieClip and a TextField. My question is: how can i access the MovieClip / TextField from my class? (i want to add a MouseEvent to the MovieClip, also i want to change the text in the TextField).

Thanks in advance.

Grabbing BitmapData Library Item And Adding To Display List
I can't seem to get this to work with BitmapData library items, though it is working for the MovieClip items...

I have a utility function which grabs items from the library

public static function create(className:String):Class
{
return new (ApplicationDomain.currentDomain.getDefinition(cla ssName) as Class);
}


Here is the code i'm using to add the BitmapData to the stage...

var ChromeBackground:Class = Utilities.create("mc_chromeBackground");
var chromeBG_BD:BitmapData = BitmapData(new ChromeBackground());
var bmp:Bitmap = new Bitmap(chromeBG_BD);
this.addChild (bmp);


The BitmapData object isn't showing up on screen. What am i doing wrong??

THANKS in advance!!!
Lori-

Create Three Instances Of A Library Item Inside A Parent Movie, Then Assign Behaviors
I want to create three instances of a library item inside a parent movie, then assign behaviors to those three items...

My brain tells me this code would work, but the reality is it doesnt, even though the debugger lists the objects exactly like I set them up:

ActionScript Code:
// create the parent movie
var Movie1:MovieClip = new MovieClip();
addChild(Movie1);

// use a loop to load in the cloned library items, name them, and assign behaviors
for (var i:int = 1; i < 4; i++) {
var subMovie:MovieClip=new libraryClip;
subMovie.name="sub"+i;

Movie1.addChild(subMovie);

subMovie.x=i*20 // this spaces them apart on the stage

subMovie.addEventListener(MouseEvent.MOUSE_OVER,showName);
    function showName(e:MouseEvent){
        trace(this.Movie1.subMovie.name)
    }
}

I'm banging my head against this, and I feel like the solution is going to be a fundamental breakthrough for me...

Help?

Add Item After Selected Item In Tree Component?
I've got a tree component which works great, but I'm trying to add an item at a particular location (immediately after the item they select) into the tree.

The problem is that I'm trying to add an item within a branch. I'm using myTree.getDisplayIndex(myNode) to get the position within the tree, but it gives the location relative to the entire list, but I need to get the position relative to the parent (which is what myNode.parentNode.addTreeNodeAt is trying to write to)...

Anyone know how I can get the position of the item the user selects relative to it's branch???

Thanks!!

How Do I Stop Carousel On Item When Item Is Clicked On?
Yeah ...some of us are still trying to tweak the carousel... I need to know how to stop the carousel when an item in the carousel is clicked on. Of course I'd also like to have that item come to the front and center as well. This carousel is done without XML.

Any help would be greatly appreciated.

here's my current code:

var numOfLogos:Number = 6;
var radiusX:Number = 300;
var radiusY:Number = 50;
var centerX:Number = Stage.width / 2;
var centerY:Number = Stage.height / 2;
var speed:Number = 0.05;

for(var i=0;i
{
var t = this.attachMovie("item"+(i+1),"item"+i,i+1);
t.angle = i * ((Math.PI*2)/numOfLogos);
t.onEnterFrame = mover;
}

function mover()
{
this._x = Math.cos(this.angle) * radiusX + centerX;
this._y = Math.sin(this.angle) * radiusY + centerY;
var s = this._y /(centerY+radiusY);
this._xscale = this._yscale = s*100;
this.angle += this._parent.speed;
this.swapDepths(Math.round(this._xscale) + 100);
}

this.onMouseMove = function()
{
speed = (this._xmouse-centerX)/1500;
}



//INFO PANELS//
phInfoPanel_mc._visible = false;



//NOW FOR THE CLICK ACTIONS//

item0.onRelease = function () {
phInfoPanel_mc._visible = true;
phInfoPanel_mc.swapDepths(Math.round(this._xscale) + 1000);
}

Make Item Grab Another Item
I am working on a game right and i want oneitem that when it touches the other stays with it like glue here is my code:

instance name:

i have a guy _root.player.hand
A ball _root.ball



so I put on the ball this code....

onClipEvent(enterframe){

if(this.hitTest(_root.player.hand)){

this._x = _root.player.hand._x;
this._y = _root.player.hand._y;

}



When the hand touches the bal he ball goes where the hand was originaly and that is it it never moves again.

can some one help ???


}

Var A:Item = New Item("Business", "+", Textsize, Color, Alignment)
Hi all,

I am new to AS3 and have spent a few weeks to figure out how to create a class which have 2 TextFields - the first textfield is either a "+" or " " and the second one is some text ... Since there are over 50 items, I think it will be good to create a class instead of using symbols in flash. I need to adjust the font size, font color, alignment, rotation inside the class.


Example :

var a:Item = new Item("Business", "+", textsize, color, alignment,rotation)

I have the following code which works in timeline but don't know how to put it in a class...

Can anyone help me out... Thanks in advance !!!

--------------------------------------------------------------------------------------

var element01:Sprite = new Sprite();

addChild(element01);

var cFont:String = "Arial";
var cTitle:uint = 0x999999;
var cContent:uint = 0xc4b789;
var cContainer:uint = 0x7c7f4f;
var c12:uint = 12;
var c10:uint = 10;

var myFont:Font = new EmbedArial();

var txtFmt_gContainer:TextFormat = new TextFormat();
txtFmt_gContainer.font = myFont.fontName;
txtFmt_gContainer.size = 24;
txtFmt_gContainer.font = cFont;
txtFmt_gContainer.color = cContainer;
txtFmt_gContainer.size = c10;
txtFmt_gContainer.align = "right";

var item:TextField = new TextField();

item.autoSize = TextFieldAutoSize.LEFT;
item.defaultTextFormat = txtFmt_gContainer;
item.embedFonts = true;
item.text = "business";
element01.addChild(item);

item.x = 10;
item.y = -10;

item.rotation = -8;

var sign:TextField = new TextField();

sign.autoSize = TextFieldAutoSize.LEFT;
sign.defaultTextFormat = txtFmt_gContainer;
sign.embedFonts = true;
sign.text = "+";
element01.addChild(sign);

--------------------------------------------------------------------------------

Florence

Sound Only Attaching From Preloader Library Not Main Movie Library
Hi guys, i've got my main movie with sounds used in classes attached from the library via attachSound. works fine when run on its own, but when run through a seperate preloader swf it only works when the sound is in the preloaders library.

Any help would be much appreciated.

Shared Library Problem (Library File Loads Twice)
What I'm trying to do:
Share a button in one Flash file for use in an imported Flash file.

The problem:
My first Flash file is loaded twice for some reason: once for the initial load, and again when the second, imported file calls on the shared library items.

The players:
FLA/SWF - <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span> (104k)
FLA/SWF - <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> (54k)
SWF - <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">loading</span> (5k, preloader)
BT - <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-button</span>, with MC <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-ani</span> inside the button

The details:
The preloader, <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">loading</span> loads 104k worth of data, all of <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span> shows up. It is sharing a button (see below) in its library, <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-button</span>.
Within <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span>, <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> then loads. The preloader loads 54k worth of data, the entirety of <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span>.

Here's where the problem occurs:
<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> has loaded correctly; the preloader is in the first frame, so we know this to be true.
<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> is completely loaded; the file is 54k, and 54k are shown to be loaded as seen in the preloader.
However, after loading, when <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> is to go to Frame 2, it chokes. It takes twice as long as <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> to load (therefore roughly 108k), before Frame 2 shows up.
After about 20 seconds on a 56k modem, everthing shows up and procedes normally, happily ever after.

What I'm pretty sure is causing the problem:
When <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> goes to display the shared button on Frame 2, I'm pretty sure it's loading <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span> again (104k), in order to get access to its shared library. (Even when I delete the large image so <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> is only mere bytes, it still acts like its loading about 104k.) This is obviously no good.

Therefore, the million-dollar question is:
Why is my shared library loading twice, when it's shared? In other words: How can I share the library items in <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span> so that they can be used in <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span> without loading the first file all over again?

Symbol linkage:
<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-button</span> in <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span>:
[x]Export for runtime sharing
[x]Export in first frame
URL: tour.swf

<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-ani</span> in <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span> (<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-ani</span> is an animation that plays when the user rolls over <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-button</span>):
[x]Export for runtime sharing
[x]Export in first frame
URL: tour.swf

<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-button</span> in <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">main-entrance</span>:
[x]Import for runtime sharing
URL: tour.swf

<span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">travel-ani</span> in <span style="font-family:'bitstream vera sans mono', 'courier new', courier, fixedsys; background-color:#ccc;">tour</span>:
[x]Import for runtime sharing
URL: tour.swf

Anyone Know If Something Like This Exists?
i use flash but, i have problems with actionscripting and programming in general. i understand more or less how it works and the logic behind it, but i get extremely confused when trying to implement something. (left brain right brain thing)

here's the idea. in flash the default button instance 'states' only allow for 'off', 'on', 'press', 'over'. that doesn't allow too much room to do intense buttons and is kind of a pain to do animated states of buttons. so, button mc's is the way to go. i think a good idea would be to develop either a component or actionscript located in one area (the timeline) for convenience and organization that could easily be applied to any 'button' with multiple functionality and states. then say, all you need to do is create your mc button and name the instance on the stage and use the needed functions from either this component or the as in the timeline.

some button states suggestions:
'off'
'over'
'out'
'press'
'release'
'on'
'visited'

does anyone know if something like this exists? a component or something where you can just utilize these 'states' and then apply functions to them as needed.

Reference External Library Movieclip In Library With AS3
Hello, i am able to load at runtime a library asset in flash cs3. i do this by setting up its linkage property and setting its base class. for eg

Class: MyButton
Base: flash.display.MovieClip

then in my document class, say i had com.kofi.InitializeTemplate, my class looks like this

package com.kofi
{
import flash.display.MovieClip;
import MyButton;

public class InitializeTemplate extends MovieClip
{
var testButton:MyButton;

public function InitializeTemplate():void
{
trace("the button class has been called");
testButton = new MyButton();
addChild(testButton);
}
}
}

however, once i bring in an external library asset(which i have already exported and set it base class etc), i am unable to call this shared library asset with as3. anyone know what i am talking about?

Copyright © 2005-08 www.BigResource.com, All rights reserved