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




A Quickie - The 'as' Operator



I'm optimising some old code and have a question about the use of the 'as' operator.

If I have a reference to an object and know its type, how should I cast it to avoid coercion errors?

In the past I used;


ActionScript Code:
SomeClass(my_object).someFunction();

but recently, I wonder if this is better;


ActionScript Code:
(my_object as SomeClass).someFunction();

Is there any performance advantage of using one versus the other, and if so, do you know why? I can't find this documented anywhere.

Thanks!



ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0
Posted on: 08-13-2008, 12:18 PM


View Complete Forum Thread with Replies

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

Another Quickie
how can you return the height/width of your movie using A/S. I made a movie with a text box and used the code textfield1 = _height, but this returned the height of the text box. I also tried it putting _root, _level0 in front of _height, but with no success.

Thanks
Mark

Just A Quickie...
is there any function in Flash to return the magnitude of a number i.e. -17 would be returned as 17. and yes i know that you can do it by taking the square root of the square of the number but i don't want to do it that way

cheers

Just A Quickie
well i hav transitions in the movie.. (ie:guestbook, news, etc) So when the user clicks, ie: news, and their now in news section.. when they click on news again it will remain the same w/o any transition.

good example of what i'm talkin about: http://www.michaelwilson.com/v2/popup

Quickie...
I am attempting to open another browser window at a specified size with only a few of the normal window properties. I know Javascript is used to do this in html but what is the syntax for Actionscript?

I am aware of this much:

getURL ("http://www.thepage.html", "_blank");

But that's about the extent of my minimal brain power. I would like the window to be 710x275 with nothing else except the scrollbar and a very small border.

Anyone know this trick????

THANKS,

A Quickie
It seems as if Flash MX supports loading MCs from the Library. Is this true...so I can load MCs from the library using loadMovie?

Thanks!

A Quickie
for the condition to be true i want the mc "page"'s x-position to be greater than -2 but smaller than 2.

-2<x<2

How do i write that in actionscript?

if (pages._x == ?????????) {

thanks

Just A Quickie...
If I use loadMovie or loadMovieNum, will the loaded .swf adopt the parent movie's frame rate, or does it retain its own, independant frame rate if different from the parent one?

Cheers.

A Quickie, Thanks
Hi there,

how do i publish flash as a web.

I made a Flash5 file, click publish as html+swf, upload the html to my site, but doesn't show up.

is there anything i miss?

Another Quickie Thanks
is there any function in flash5 that delete unused symbols in the library after i finish my work?

thanks

Just A Quickie
Can someone remind me the code for when I'm controlling a movie loaded at level 1 from level 0.

_level1.something!!!

Hope you can help, cheers!

Quickie, I Mean It Too :)
If I have a rollover flash button wherethe button itself changes color and another area displays the button title only bigger, how can I remove the "clickable area" or link to the "other area" that just displays the title?

The reason I ask is because, I imagine that if I try to display all the buttons' titles in this same area, there will be a mess of links overlapping...can I just undo a link to a symbol within a button?

thanks

Quickie(s)
if you have two layers, the bottom containing buttons....is there a way to make the top layer "not-clickable" until the layer is moved out of the way...

meaning...if the top layer is a door I don't want the viewer to be able to click the links until the door is open revealing them.


also if you are using load-movie to launch external swf's, how do you get the scene to auto load the first movie when the page is loaded? thanks

>>>> Quickie Help <<<<<
whats the code to hide mouse in flash, and to make a movie clip follow the mouse.

Just A Quickie
Anyone know how to increase the size of the area around the stage, so you can position stuff a long way from the stage?

Anyone?!

Quickie I Think? AS ?
MX

I animated a headlight switch (auto) The switch has two positions (park and headlights). I want to use the mouse to "pull" the switch out to either position.

I thought it was "on (dragOut) , put that doesn't allow me to pull the switch out to the last position.

I guess I need to press on the mouse, grabbing the object, then on release, the object stays put. on (releaseOutside)?

thanks

Just A Quickie
I have been using flash for a while at university and have mainly used it of rmaking artefacts, games and such like. I have recently been asked to make a wbsite and would like to further my skills.
I was wondering whethe it is better to make seperate swf's for each button off the main menu - for instance if a button is clicked then the flash player will load up a seperate swf. I have always created everything as one file using frame labels, but am sure that people do, do this!

Lastly, does anyone know of any good tutorials which show how to incorperate preloaders.

A Quickie I Believe
okay i made an intro for someone and when that intro is done on the index page they want it to automatically load into their main url. This isnt a flash movie website. So what I'm asking is, Is there a way to actionscript in some code so when the intro is complete it will automatically load the url?
Thanks
Ryan

Just A Quickie
okay this should be fast

i am trying to do an if statement with an instance name that is "rocknumber" + count where count is a variable.

Code:
if (_root.rocknumber+count=="rocknumber7){
trace("Loop has found rock seven!")
}

how would i format this??

thx a ton

Quickie...
hey, i was wondering how to access the selected item of a list component. I tried a few things, like wholeclass(the name of my list component).selectedItem.text,.name,.label? and anything else that came to mind, but all i would get it return is 'undefined'. anybody here happen to know how to use a list or a place where i can find the complete listing of how to use, access and edit the list componet ?


Code:
on (press){
trace(_root.wholeclass.selectedItem.name)
}
doesnt work... nor do any variations i could think of.
and also, anybody else know how to find a certain item in a listbox like such:

Code:
trace(_root.wholeclass.items[0])
but have it actually work...


thanks a lot

Just A Quickie.
Ive got some code....

on (rollOver) {
tellTarget ("decks") {
gotoAndPlay(6);
}
}

which is all fine and dandy. What i now want it to do is check to see if it is already on frame 6 or not... probably an 'if/else' kinda thing which i did ages in flash 5.... now im blank. Can anyone fill in my blanks? Cheers.

XML Quickie, It Should Take A Sec.
I'm trying to display a link in a text box, and I am importing the text for the link from an XML file. the text on the file is


<Heading Number="News 3"> http://www.kirupa.com </Heading>

and my code for the link is

News3 = "<a href='" + _root.LoadedNews.childNodes[2].childNodes[0].nodeValue + "'target='_blank'>" + "News3" + "</a>";
}


I get the link to work, but I get an extra "http:// appearing at the window. If I get rid of it on the XML file, then it doesn't turn into a link. What should I do??? I really appreciate the help!

Really Quickie
anybody got any idea why this wouldnt work???
im trying to open up an html page that i have created in dreamweaver-( it contains a jpeg of a map) in a new window.

OnRelease{
getURL ("map.html","_blank");
}

Anthing seem up with that?

Just A Quickie.
Ive got some code....

on (rollOver) {
tellTarget ("decks") {
gotoAndPlay(6);
}
}

which is all fine and dandy. What i now want it to do is check to see if it is already on frame 6 or not... probably an 'if/else' kinda thing which i did ages in flash 5.... now im blank. Can anyone fill in my blanks? Cheers.

Quickie
Hey all.

I was wondering would it be possible to take a graphic of a world map and use flash so that when users click a continent the flash then zooms into a continent view? Then the same again for countries? then I could use dynamic text for rolling over points dotted in those countries to display basic information couldnt I??? Im new to this and im just making sure my idea sounds feasable... Thanks

Quickie
AS seems to have been disables in CS3. Does anyone know why this might be? Nothing is working at all!

It's in an AIR app but it seems that the problem is the As...

Quickie On Sounds
I wanna have sounds played in my movie via action script. However, the help file was rather vague on this to say the least. Anyways, from reading the helpfile, I got the idea that all you have to do is this:

In a keyframe, I added the following code:
fire = new Sound(this);
fire.attachSound("boom"); //the sound I want is called "boom" in my library

And in a movie clip, when I want the sound played on a certain action, I have the code:
_root.fire.play();

Now, from the help file I thought this was all there is to it, but apparently it isn't. Any quick ideas? I basically want a sound to be played when called on in some action script later on in the movie.

Fancy A Quickie?
Sorry this is probably somewhere in the help files, but I couldn't find it...

how can I change the font size of a dynamic text box with the html tags enabled? I tried <font size=20> but this didn't want to work.

Thanks

I'll Make This One A Quickie...
Okay...

I have a variable:

_root.crosshair.score

In another scene I have another variable:

_root.finalscore

how do I make the final variable equal the first variable?

Thanks

A Math Quickie
How come I am not able to make this variable a random number? I keep getting this error:
**Warning** Scene=Scene 1, Layer=Layer 1, Frame=1: Line 2: Case-insensitive identifier 'number' will obscure built-in object 'Number'.


Code:
on (press) {
number = (Math.floor(Math.random()*10+1));
}

Quickie Can Flash Do This?
I want to insert an image into flash (its a high contrast image, just dark black and white). And I want to make it so that things under the black parts of the image show through (so black parts would have 50% alpha), but that things under the white sections of the image show through completely (white sections have 0% alpha).

Obviously I can't make different parts of the bitmap different alpha transparencies... so is there any way I can do this?

Roll Over For A Quickie
I modified a bit of script from someones posting last week sometime..

on(rollOver){
x = _root.pageOpen;
if(_root.pageOpen != undefined){
_root[x].gotoAndPlay("exit");
}
if(_root.pageOpen != _root[name]){
_root[name].gotoAndPlay("open");
}
}

it fades in and out different movieclips when on roll over of different buttons.. my buttons are generated from an xml so the movie clip name is a variable[name] ..

the prob I can't seem to fix is that if a button is active when you rollover a second time it makes the picture flash..
I thought the line:

if(_root.pageOpen != _root[name])

would work but no joy.. any ideas???

Quickie Question
when applying transition effects to a frame, is it possible to apply than same across miltiple frames at the same time? or do i have to open each frame seperately?

quick question...i hope...thanx for your help!!

Quickie- New To Scripting
Using MX

I have several movie clips in the main frame. You can select any of them ("active") and they turn red in color (wiring diagram). I would like to print out those that are "active".

Question: Does the print command come first in the script?

code:
on (release){
print;
if("_root","bmovie" == "active");
else(
("_root","bmovie" == "gray"));
}


Everyone have a safe new year!

Tween Quickie
MX
I was having a little trouble building this tween. I have a sample to work from courtesy of the "group". I could get mine to work, so I went back to its simplest form and created a new one.

Still not "tweening". I have attached the simple one, if someone would look at it a tell me where my mistake is.

I get that little yellow triangle error in the prop box.

Thank You and go easy during the big game!

Tweening Quickie
What is the secret to accurately placing the cover shape over the object you are animating(tweening)?

I am animated lines that draw by themselves using "tweening", but I constantly using trial and error in placing the "cover box". Sometimes I place it right the first time, but most of the time it either doesn't cover line or doesn't drawn the entire line. Always looks and works fine in the edit mode of the mainframe.

Can those "lines converted to fill" be allowed to change colors, similar to changing colors of a non-converted line?

Thank you

2d Array Quickie
Hey,

can someone show me the code to create a 2d array, lets say 10 columns by 15 rows so i can see what maps to what.

Many thanks,

Gareth

Just A Quickie - One Or Two Words Will Do
Hi there - I've used the tuturial on THIS page to help transition my pages smoothly: http://www.kirupa.com/developer/mx2004/transitions.htm

Everything is working fine; however, if I move the buttons and the A/S off the main timeline, I am not able to load the relevant sections anymore. I just keep loading the same swf over and over... Section 1.

This is the code that is supposed to sit on the main timeline to enable the transitions:

on (release) { if (_root.currMovie == undefined) { _root.currMovie = "main"; container.loadMovie("main.swf"); } else if (_root.currMovie != "main") { if (container._currentframe >= container.midframe) { _root.currMovie = "main"; container.play(); } } }

The MC that I've moved everything into is called 'fluid'.

I know I need to change the path to the container, and I've tried the following to try and reach it:

_root.fluid.container.
fluid.container

and neither have worked.


Does anyone have any urgent suggestions? I know it's a simple fix - I just can't see it!

AS2 - LoadMovieNum Quickie
Gentlemen (and few ladies),

Previewing through my CS3 ide my project loads just fine.

when posted to server, however, the swfs that should be loaded via simple


Code:
on(release) {
loadMovieNum ("url", level, "GET")
}
...doesn't work. What am I overlooking?

The external swfs that are being loaded are in the same root dir of the main swf. (I have tried using an absolute URL path ("http://exampledomain.com/external.swf") and the more simple ("external.swf").

I have tried the same combo as above but with the "POST" variable. no avail.

****** side question, what is the proper use of "GET" and "POST" ?

<fingers crossed>

Thanks,

Quickie Q About Refreshing
I've searched the threads, and the answer is nowhere to be found...

All I want is a tip on how to refresh the current html page my SWF is residing in. I'll be using it in a button...

Sound hard? I think it might be something like getURL(java script:refresh); or somethin'...

Another Quickie : This Time Bout XML
can i use html formatted text within my xml? wht are the consequences, if any?

Quickie On Variable Expressions
hi...

just a quick question, when im defining a variable as a web address should it be as an expression? for instance...

mail = "http://www.hypnoticmedia.co.uk/codebook/mail.php";

Quickie...ypos And Scrolling
I have a vertical scrolling menu and instead of moving the menu to the defined y position below I want my buttons to on press scroll to that position and on release stop.

As the code is now, when you click the down button it tells the menu to set the y pos to 86.5. I want it so when you click on it scrolls instead of jumping right this position. Thus when you release the scroll before it reaches 86.5 it stops.

I think you only need to edit the _root.ypos code but I could be wrong.

Thanks

on (release) {
_root.ypos = 86.5;
tellTarget ("_root.control3") {
gotoAndPlay (2);
}
}

Code Check, Quickie
I received this info for passing variables along from a combo box into an asp page and I need to have the syntax of the code checked.

Is this correct
choice = comboboxinstance.getSelectedItem()to your button handler.

My combobox is called 'combobox' and it has green and blue labels as well as green and blue data fields

The asp should see the variable "choice" correct

Quickie About Alpha And Control
can movie.swf control the alpha of movie2.swf and do ya know the actionscript?

Quickie On Blinking Object
MX
I have an object converted to a MC. In that MC, I have a Label Layer and a Graphics layer. The graphics layer changes the color of the object. I would like to "call" the object by the label "blink" in the MC and have it blink until I call for the stop label. I also have an Action layer w/ a stop in frame one to keep it from blinking from start to finish. I'll keep looking until someone sticks the answer in front of my face, cuz I'm sure it right there.

Thank You

Scrolling Content - Quickie
I found this code that allows me to scroll content inside of a MC using a custom scroller. But what I need to change is this. I am going to have multiple frames inside of the MC with different content and I want the scroller to be able to determine how far to scroll based on that height. Here is the code

onClipEvent(load){
goY = this._y;
myY = this._y;
ySpeed = 0;
clicked = false;
delay = 20;
//I need to change barDis to equal the hieght of my movie.
barDis = 119;
barPercent = 0;
}
onClipEvent(enterFrame){
if(math.round(myY) != math.round(goY) || clicked == true){
barPercent = (_parent.scrollbar.bar._y/barDis)*100;
goY = -153.1 - ((155/100)*barPercent);
myY = this.movies._y;
ySpeed = (myY-goY)/delay;
this.movies._y -= ySpeed;
}
}

I need barDis to set the scrollable area based on the ._height of the mc. Once again this will change depending on which frame you are on.

Any help would be appreciated.

Scene Transitions - Quickie
mx2004

Scene 1 has no stops in it after the first frame. All layers end on the same frame number. A MC starts the animation, again no stops.
code:
on (rollOver) {
_root.MC_Tw_IgnitionSW.gotoAndStop("On");
_root.gotoAndPlay("Key_On");
}
on (rollOut) {
_root.MC_Tw_IgnitionSW.gotoAndStop("Off");
_root.gotoAndStop(1);
}
on (press) {
_root.MC_Tw_IgnitionSW.gotoAndPlay("start");
_root.gotoAndPlay("Key_Run");
}
on (release) {
_root.MC_Tw_IgnitionSW.gotoAndStop("On");

}

Yet scene 1 will not "auto" to scene 2. Any quickie ideas.

If I put in on (release) gotoAndPlay (scene 1, 1), then it doesn't let the sound frames to finish.

Thanks

Control _levels - Quickie
What is the proper syntex to controlling levels. I have 2 swf's (main and insert) main.swf loads insert.swf into it. I have a button on insert.swf that tells main.swf to go to frame 2. I can't get this to work and I've tried a bunch of things. Any help would be huge.

I've tried...

Code:
on(release){
this._parent.gotoAndStop(2);
}
//
on(release){
_level1.gotoAndStop(2);
}
//
on(release){
_root.gotoAndStop(2);
}
//
on(release){
_parent.gotoAndStop(2);
}

Quickie Both Swf And Html Required
are both the swf and html required to be uploaded in order for the swf to play? Is that only for the index page?

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