Actionscript focus
Hello
When I'm typing code in the actionscript editor (Flash CS3)
after some moments/seconds
the editfield loses focus. So I have to click (again) in de
editfield to put code in it.
And then, after 3 or 4 seconds I have to click again because
my typing does go somewhere
This is crazy !
The problem never accurd in the previous Flash version.
Thanks for any help !
on mouseup or click, if the mouse is down, you can use:
stage.focus=outputText;
if the mouse isn't down, you can don't need a listener to trigger the above.
Similar Messages
-
Next and Previous Buttons, n00b edition
OK, I am trying to construct a "timeline" flash file, where
basically you click either a next or previous button to move
through different frames, and I think I know how to do everything
other than the next and previous buttons. Two questions:
Would this be easier as AS2.0 or AS3.0?
If I use AS3, would this code work, and is "my_mc" simply the
name of the layer with the navigable frames?
next_btn.addEventListener(MouseEvent.MOUSE_UP,buttonPressed);
prev_btn.addEventListener(MouseEvent.MOUSE_UP,buttonPressedprev);
function buttonPressed(event:MouseEvent){
my_mc.nextFrame()
function buttonPressedprev(event:MouseEvent){
my_mc.prevFrame()
Sorry if this is confusing, I am such a n00b I don't even
know how to ask questions properly.sholditch,
> This is a huge help and one of the better explanations
of AS
> coding I've ever seen. Thanks a ton.
Thanks!
> However, I think I may be jumping ahead too much.
Sure, no worries. It's definitely dizzying at the beginning.
> Follow up questions, n00b style:
>
> 1. What would be the equivalent of the nextFrame()
method
> for previous? Tried searching help and googling, but
getting
> too much other stuff to wade through.
Google absolutely rocks, but I hear ya ... you have to be
willing to
wade through numerous search results. Fortunately, the Help
docs usually
get you directly to your answer -- and quickly, at that -- if
you just know
how to navigate them. If you're using Flash CS3, the Help
docs are local,
though optionally available online. If you're using Flash
CS4, the docs are
online and open in a browser, in either case, what you're
looking for
specifically is the ActionScript 2.0 Language Reference (if
you're using
AS2) or the ActionScript 3.0 Language and Components
reference (if you're
using AS3).
AS2:
http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=Part2_AS2_LangRef_1.html
AS3:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/index.html
In the case of AS2, you'll click on the lefthand side. Open
up
"ActionScript 2.0 Language Reference," then "ActionScript
classes," and
you're in. In the case of AS3, you'll see the classes already
listed on the
lefthand side.
Now ... you've coded up your button, which means you
consulted the
Button (AS2) or SimpleButton (AS3) class to see what was
available to you.
(I'm speaking hypothetically, of course. When you've become
more
comfortable with the docs, this will often describe your
initial steps.)
You want to code up a button symbol, so that means you've
looked up the
Events heading for the appropriate class to see what this
object can react
to, such as a button click. You've found your event --
onRelease or
MouseEvent.CLICK -- and have associated that event with a
custom function.
Now, you're on to the next step. In this case, the object
you're
looking for is no longer a button. It's a movie clip, because
you want this
function to send the main timeline forward or backward.
Again, your first
question is always: a) what object am I dealing with? Here,
it's the
MovieClip class, so that's where you flip to. Your second
question is: b)
what category am I looking for? If characteristics, look up
Properties; if
something the object can do, look up Methods; if something
the object can
react to, look up Events. In this case, you want to send the
timeline
somewhere. That's something the timeline (that is, this
particular movie
clip) can do. The things-an-object-can-do category is
Methods, so that's
where you flip to.
You'll see a decent selection in either language, including
the common
gotoAndPlay(), gotoAndStop(), and so on. You'll also see
nextFrame() and
prevFrame(). Bingo! (Note, both versions of the language rely
on something
called inheritance, which behaves just like it sounds. Just
as we humans
inherit traits from our predecessors, most classes inherit
traits from other
classes up the family tree. In the AS3 docs, you'll see a
"Show Inherited
Public Methdods [or Properties, or Events]" hyperlink. If you
need more
detail, be sure to click that link. In the AS2 docs, the
inherited items
are listed in a box beneath each heading. Any given class may
or may not
have inherited items.)
So you really don't have to wade too far. Think of what
object you're
dealing with, then jump to the relevant category.
> 2. How do I make the next and previous buttons the only
> controls that will move to the next or previous frames?
I
> plugged in the code into a separate as_layer and when I
> test the scene it just goes through the frames
automatically.
Movie clips (including the main timeline) just animate
naturally -- they
*want* to move -- so if you want a timeline to stop, you have
to instruct it
to. Here again, you'll look up the MovieClip class and,
because you want to
find out how to *do* something (how to stop this movie clip),
you'll jump to
the Methods section. Sure enough, there's a MovieClip.stop()
method.
In frame 1 of your main timeline, simply type stop(), and
that'll do it.
The reason it works is because you're invoking a MovieClip
method on a
MovieClip instance -- the main timeline. If you wanted to
stop a movie clip
symbol, you'd have to give it an instance name, then invoke
the method on
that particular instance, like this:
myMovieClip.stop();
... in which case, myMovieClip is the instance name, and this
clip happens
to site in the same timeline as this code appears.
Alternatively, you could enter the timeline of that movie
clip and
simply put stop() in its own first frame. That would do it
too. In either
case, you've invoked a MovieClip method on a particular movie
clip. All you
ever need is an object reference (implicit, because you're in
that object's
scope) or an instance name (or a variable that, by some other
mechanism,
refers to a particular object) and then you're set. With that
reference in
hand, you simply name the reference, put a dot, then invoke
the desired
property, method, or event.
In the case where you simply invoke stop() on the main
timeline, you
*could* reference the main timeline directly, like this:
this.stop();
The "this" keyword is a special reference that refers to
whatever scope
its in. Because your code appears inside a keyframe, its
scope is the movie
clip in which that keyframe appears, therefore "this" -- in
that context --
refers to that movie clip. But as I showed earlier, you can
also simply
leave off the prefix object reference because Flash will know
what you mean
(that is, which movie clip you mean).
Eventually, when you're more comfortable, you'll reference
instances of
other kinds of objects, such as sounds, text formatting
objects, and more.
In those cases, your object reference -- an instance name, or
a variable --
will act the same way, but you'll only be able to invoke
functionality from
the relevant class.
If you have Sound instance, for example, you couldn't do
this:
mySound.gotoAndPlay(15);
... because sounds don't have timelines, and the Sound
class's Methods
section doesn't feature a gotoAndPlay() method. And that
totally makes
sense, right?
> If you have a beginner's guide to actionscripting,
focused
> on AS3, I will buy it today.
I'm happy to keep answering your questions here, but yes, I
do have a
few books you might be interested in. If you're using Flash
CS3, you might
consider Tom Green's and my Foundation Flash CS3 for
Designers (friends of
ED) (
http://tinyurl.com/2k29mj),
and if you're using Flash CS4, you'll want
the current version of that book (
http://tinyurl.com/5j55cv).
Bear in mind,
these are "foundation" books, so they cover all of Flash, not
just
ActionScript. Still, there's tons of ActionScript in either
one
(exclusively AS3, by happenstance), and we've received
positive feedback on
the ActionScript Basics chapter, in particular.
I also recently finished an AS2-to-AS3 migration book for
O'Reilly
http://tinyurl.com/2s28a5),
but that one may not be especially useful for
you, because it focuses more on developers who have a basic
understanding of
AS2 but feel bewildered when it comes to AS3.
There's also my blog, (quip.net/blog), which has tons of AS2
stuff, and
is slowly growing new AS3 content. One of my co-authors for
the O'Reilly
book, Rich Shupe, co-authored an ActionScript 3.0 book
specifically for
beginners, so take a look, read the reviews, and see if the
publisher offers
sample chapters. They often do, and that's usually a good
indicator -- to
me, anyway -- of how a particular author's style gels (or
doesn't gel) with
your particular learning style.
David Stiller
Contributor, How to Cheat in Adobe Flash CS3
http://tinyurl.com/2cp6na
"Luck is the residue of good design." -
Setting textfield focus in ActionScript 3.0
I am using an event handler to listen for MOUSE_UP on stage_mc to let the user create text and images on the screen. I have buttons above the stage that set a variable, then the variable determines which action occurs with the mouse event.
I would like the user to be able to enter text, and can create an input text field on the stage, but the user then has to click inside the text field to begin typing. Because of the event handler, this 2nd MOUSE_UP repositions the text field, although it IS successful in setting the focus.
Ideally, I would like for the user to be able to create the input text field by clicking on the stage and then begin typing without having to click a 2nd time. It seems simple enough, but I still don't understand OOP enough to decipher the help pages available within the program.
Does anyone have any suggestions? Here is my code (some of the included variable are set in previous lines):
//Setting up the Text Field parameters
var outputText:TextField = new TextField();
var textFormat:TextFormat = new TextFormat();
// Enabling the input tools
function startDraw(event:MouseEvent):void {
if (currentTool.name == "lineTool_mc") {
newLine.graphics.moveTo(event.localX, event.localY);
stage_mc.addEventListener(MouseEvent.MOUSE_MOVE, drawLine);
} else if (currentTool.name == "textTool_mc") {
textFormat.color = 0x336699;
textFormat.size = 48;
textFormat.font = "Times";
outputText.defaultTextFormat = textFormat;
outputText.selectable = true;
outputText.x = event.localX;
outputText.y = event.localY;
outputText.background = false;
outputText.border = true;
outputText.autoSize = TextFieldAutoSize.LEFT;
outputText.type = TextFieldType.INPUT;
designContainer.addChild(outputText);
} else if (currentTool.name == "brushTool_mc") { ...on mouseup or click, if the mouse is down, you can use:
stage.focus=outputText;
if the mouse isn't down, you can don't need a listener to trigger the above. -
Javascript popups that open in same window causing focus problem
I have been using javascript popups in actionscript buttons
for some time with no issues. However, on a specific movie I have 2
button links, each of which opens a pdf file. I need each pdf to
open using the same new window to avoid multiple new windows
opening.
This works fine on the first link I open - the new window
appears on top of the main window. The second link, however, opens
underneath the main window despite the focus() code. This only
happens in IE - works fine in Firefox.
Code used:
link3_btn.onRelease = function() {
getURL
("javascript:NewWindow=window.open('docs/first.pdf','newWin22','width=700,height=500,left =1
0,top=10,toolbar=No,location=No,scrollbars=Yes,sta
tus=Yes,resizable=Yes');NewWindow.focus();void(0); ");
link4_btn.onRelease = function() {
getURL
("javascript:NewWindow=window.open('docs/second.pdf','newWin22','width=700,height=500,lef t=
10,top=10,toolbar=No,location=No,scrollbars=Yes,st
atus=Yes,resizable=Yes');NewWindow.focus();void(0) ;");
Any help would be appreciated. Thanks.This is how the code should look:
link3_btn.onRelease = function() {
getURL
("javascript:NewWindow=window.open('docs/first.pdf','newWin22','width=700,
height=500,left=10,top=10,toolbar=No,location=No,scrollbars=Yes,status=Yes
,resizable=Yes');NewWindow.focus();void(0); ","_self");
link4_btn.onRelease = function() {
getURL
("javascript:NewWindow=window.open('docs/second.pdf','newWin22','width=700,height=500,lef t=
10,top=10,toolbar=No,location=No,scrollbars=Yes,st
atus=Yes,resizable=Yes');NewWindow.focus();void(0) ;","_self");
} -
Pausing swfs and audio in a browser when the tab is out of focus
I'm trying to code my flash file so that the html will pause all swfs AND audio when the tab is out of foucs. I found this code on http://frontenddeveloper.net/wiki/index.php?title=JavaScript_and_VBScript_Injection_in_Act ionScript_3 and it works,but not completely. It only pauses the movie clips that are in the Flash file and not any that are exteranlly loaded with audio included.
How can I adjust it to pause the externally loaded swfs that are loaded to a mc within my main movie clip and the audio OR what should I use in place of this code? Someone mentioned on a different post that I needed to use a window.onblur funcition, but they didn't give details.
import flash.display.MovieClip;
import flash.utils.setTimeout;
// This is a more "safe than sorry" setting, since multiple domains
// have entry into my site. Can be removed or hardcoded if you feel
// secure or insecure, as you see fit.
flash.system.Security.allowDomain("*");
// Throw any errors around to make sure somebody actually gets them.
ExternalInterface.marshallExceptions = true;
// This is not the most ideal way to toggle animations on and off, but
// it's thorough, generic, and simple. Iterate all movieclips within
// clip, shutting them down each in turn. A better, but much more tedious
// method would be to target specific clips using dotpath notation, telling
// each in turn to turn off or on depending on what we need.
// BUT this is just a demo, and what we're really interested in is the
// event-handling mechanism that actually calls this routine, and not the
// routine itself.
function toggleAllClips(doAnim, clip) {
if ( clip is MovieClip) {
if (doAnim) {
clip.play();
} else {
clip.stop();
for (var i = 0; i<clip.numChildren; i++) {
toggleAllClips(doAnim, clip.getChildAt(i));
function animOn(e:*=null) {
toggleAllClips(true, this.mainMC);
function animOff(e:*=null) {
toggleAllClips(false, this.mainMC);
function injectPrep(e:*=null) {
try {
ExternalInterface.addCallback("jsanimOn", animOn);
ExternalInterface.addCallback("jsanimOff", animOff);
} catch (e) {
trace(e);
function injectListeners(e:*=null) {
try {
// Object/Embed ID of this movie needs to be inserted into the
// JavaScript before we actually wrap and send it to the browser:
var jsfix=js.toString().replace(/xxx/g, ExternalInterface.objectID);
ExternalInterface.call(jsfix);
} catch (e) {
trace(e);
// Using timeouts ensures the movie is actually done loading before
// these fire, helping compatibility for a few browser versions.
setTimeout(injectPrep,0);
setTimeout(injectListeners,100);
JAVASCRIPTS
JavaScript needs to be wrapped in a tag, a cdata, and a closure
function in order to be wrapped up and sent to the browser.
Note that an ActionScript function will replace all instances
of "xxx" with the actual ID used for this SWF.
We're battling some major bugs and crossbrowser idiosyncrasies
here:
1) In Internet Explorer the 'onblur' event is implemented
incorrectly (as opposed to Firefox/Mozilla browsers). It is
wrongly fired when focus is switched between HTML elements
*inside* a window. As a result, we have to use onfocusout
instead of onblur, and keep track of which element is active.
If we focusout and the active element is not the previous
active element, then we haven't actually "blurred" and dont
want to trigger Flash.
2) Firefox has problems interpreting both getElementById and
document["swf"] when dealing with "twicebaked" object/embeds.
Adobe's method of finding the swf fails to address the fact
that document["swf"] sometimes returns an array in this
situation rather than an object ref, and getElementById
sometimes confuses name and id.
3) When a window is created in Firefox, it doesn't actually have
"focus" (event though it appears to) and therefore won't "blur"
unless you actually click in it first, i.e if you open up a
window, then immediately send it to the background, it never
gets the command to halt the flash. So we have to explicitly
focus the blasted thing to get it to work properly.
4) Because of irregularities caused by Ajax, the way browsers shut
down, and other factors, there's a good chance our swf won't
be there when a blur (or focusout) event occurs. Therefore we
need an explicit check within the event handler itself.
5) Finally, we want to wrap everything inside a wrapper-closure
function, to keep everything safe from being stepped on. Lucky
us, we have to do this anyways to get everything to fit inside
a single ExternalInterface.call event.
var js:XML = <script><![CDATA[
( function() {
var active_element; // tracker for ie fix;
var bIsMSIE = false;
// Modified version of Adobe's code resolves a bug in FF:
function getSWF(movieName) {
if (navigator.appName.indexOf("Microsoft") != -1) {
return window[movieName];
} else {
// Resolves a bug in FF where an array is sometimes returned instead of a
// single object when using a nested Object/Embed.
if(document[movieName].length != undefined){
return document[movieName][1];
return document[movieName];
// Need to check for swf each time we try this because the swf may actually be gone
// because of ajax or a window closure event. Prevents error dialog from popping up.
// Future release should check for this condition and then remove the calling event
// so it doesn't keep triggering.
function animOff(){
if (bIsMSIE && (active_element != document.activeElement)) {
active_element = document.activeElement;
} else {
var logoThang = getSWF("xxx");
if(logoThang){logoThang.jsanimOff();}
function animOn(){
if (bIsMSIE && (active_element != document.activeElement)) {
active_element = document.activeElement;
} else {
var logoThang = getSWF("xxx");
if(logoThang){logoThang.jsanimOn();}
// Add the listeners. Hear ye, here ye.
if (typeof window.addEventListener !== "undefined") {
// Firefox, Mozilla, et al.
window.addEventListener("blur", animOff, false);
window.addEventListener("focus", animOn, false);
} else if (typeof window.attachEvent !== "undefined") {
// Internet Explorer
bIsMSIE = true;
window.attachEvent("onfocus", animOn);
// Another bug: window.onblur ALWAYS fires in IE, so
// we have to keep track of what we're clicking using
// another method:
active_element = document.activeElement;
document.attachEvent("onfocusout", animOff);
// Necessary to trigger toggling in FF if the page hasn't actually been clicked in and the page
// is sent to the background. Can be commented out if necessary, e.g. if you don't want the page
// popping to the top or want focus to remain somewhere else like a form field.
window.focus();
]]></script>;I added this code and it removes the externally loaded swfs. I don't want that, I want them to pause and then resume when the tab is back in foucs. Also, the main code restarts the main movie clip upon refocusing too.
Added code:
function toggleAllLoaders(doAnim, loader) {
if ( loader is Loader) {
if (doAnim) {
loader.play();
} else {
loader.stop();
for (var i = 0; i<loader.numChildren; i++) {
toggleAllLoaders(doAnim, loader.getChildAt(i));
I added the new function to all of the places that had the "toggleAllClips" function. -
How to maintain focus in input text box?
I am a complete newbie with Flash MX, ActionScript, and
everything in between. So here's my situation.
I want to make it so the user has to type in a password to
move forward with the Flash presentation. When he presses OK, it
takes him to further into the presentation (i.e. Frame 20).
On my login screen, I have a couple of layers that are
animated. Thus, I need these animations to keep looping. So what
did I do? At the end of the animation, I put in code to
GotoAndPlay(1).
Now here's the problem... When someone's trying to type in
the password, when it loops (Gotoandplay), the input box loses
focus. To remedy this situation, for frame 1, I put in the code:
Selection.setFocus("txtPassword").
What happens? Everytime it sets focus, everything gets
highlighted in the input text field.
As you can imagine, it is a headache for anyone who is trying
to type in the password because every few seconds, the whole thing
gets highlighted and he accidently types over it.
Any suggestions?1. copy the frames of your looping animation.
2. create a new movieclip and paste those copied frames onto
this movieclip's timeline
3. from your library drag a copy of the above movieclip to
frame 1 of your main timeline and attach a stop() to that frame.
4. place your login textfield and ok button on frame 1 of
your main timeline.
5. when ok is pressed (and login) passes some condition
direct your main timeline to frame 20. -
Popup Window- Button Actionscript
Does anyone have the code that combines actionscript w/ java
in order to create a popup window from a flash button? I couldn't
get this to work- on (release) {
getURL
("javascript:NewWindow=window.open('index.html','newWin','width=400,height=300,left=0,top =0,toolbar=No,location=No,scrollbars=No,status=No,resizable=No,fullscreen=No');
NewWindow.focus();void(0);");ggshow, I tried your component, but I can't figure out where
to place the
my_btn.onPress = function() {
my_popup.openWindow("
http://www.ggshow.com",
"my_window");
I would be very happy if you, or anyone else could solve this
trivial problem for me
thanks
/magnus -
I'm a student I have a final project want to deliver it after two days.
I'm making a drag and drop game, I watched a tutorial to do that.
But after ending coding I faced a weird error!
I've I checked that my code is the same as the code in the tutorial.
This is the Debug error report:
Attempting to launch and connect to Player using URL E:\FL\ActionScript\Drag and Drop Project\DragAndDrop.swf
[SWF] E:\FL\ActionScript\Drag and Drop Project\DragAndDrop.swf - 87403 bytes after decompression
TypeError: Error #1034: Type Coercion failed: cannot convert paper1$ to DragDrop.
at Targets()[E:\FL\ActionScript\Drag and Drop Project\Targets.as:23]
My `.fla` File is containing 12 Objects to drag and another 12 Objects to drop on it.
The idea here is when drop the Object on the target the Object will become invisible and the target become visible (in `.fla` file `target alpha = 0`).
I made two classes:
DragDrop.as : for the objects that I'm going to drag.
Targets.as : for the targets that I'm going to drop Objects on it.
Note: match function is to animate "GameOver" MovieClip When complete the game.
DragDrop.as:
package
import flash.display.*;
import flash.events.*;
public class DragDrop extends Sprite
var origX:Number;
var origY:Number;
var target:DisplayObject;
public function DragDrop()
// constructor code
origX = x;
origY = y;
addEventListener(MouseEvent.MOUSE_DOWN, drag);
buttonMode = true;
function drag(evt:MouseEvent):void
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
startDrag();
parent.addChild(this);
function drop(evt:MouseEvent):void
stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
stopDrag();
if(hitTestObject(target))
visible = false;
target.alpha = 1;
Object(parent).match();
x = origX;
y = origY;
Targets.as:
package
import flash.display.*;
import flash.events.*;
public class Targets extends MovieClip
var dragdrops:Array;
var numOfMatches:uint = 0;
var speed:Number = 25;
public function Targets()
// constructor code
dragdrops = [paper1,paper2,paper3,paper4,paper5,paper6,
paper7,paper8,paper9,paper10,paper11,paper12,];
var currentObject:DragDrop;
for(var i:uint = 0; i < dragdrops.length; i++)
currentObject = dragdrops[i];
currentObject.target = getChildByName(currentObject.name + "_target");
public function match():void
numOfMatches++;
if(numOfMatches == dragdrops.length)
win.addEventListener(Event.ENTER_FRAME, winGame);
function winGame(event:Event):void
win.y -= speed;
if(win.y <= 0)
win.y = 0;
win.removeEventListener(Event.ENTER_FRAME, winGame);
win.addEventListener(MouseEvent.CLICK, clickWin);
function clickWin(event:MouseEvent):void
win.removeEventListener(MouseEvent.CLICK, clickWin);
win.addEventListener(Event.ENTER_FRAME, animateDown);
var currentObject:DragDrop;
for(var i:uint = 0; i < dragdrops.length; i++)
currentObject = dragdrops[i];
getChildByName(currentObject.name + "_target").alpha = 0;
currentObject.visible = true;
numOfMatches = 0;
addChild(win);
function animateDown(event:Event):void
win.y += speed;
if(win.y >= stage.stageHeight)
win.y = stage.stageHeight;
win.removeEventListener(Event.ENTER_FRAME, animateDown);
...ThanksThank you very much for replying.
- dragdrops represents: the dragable objects.
- Targets obtaining the dropable objects by hitTestObject, then the dropable objects visible is turned to false, & the target visible turned to true.
Dragable objects is a 12 elements all of them have an instance names: paper1....paper12.
When I focused to the project I noticed that I forget to give the dragable objects an instance names!
after making the instance names to them, a new error occures:
E:\FL\ActionScript\Drag and Drop Project\Targets.as, Line 11
1046: Type was not found or was not a compile-time constant: paper1.
This error is continuing to paper2, paper3.....paper12 !
Please download my project, I must deliver it to my college in 24/12. I will never forget your favor. thanks.
https://www.dropbox.com/s/8mdg5w17vvryzso/Drag%20and%20Drop%20Project.rar | 715KB -
Pausing Flash movie on focus lost
Is there any way thru ActionScript to detect the loss of
focus at the Flash movie level, eg. browser minimize or selection
of another window, I would like to auto-pause my game at this
point. I managed to create a reasonably effective solution using
event handlers within the EMBED and OBJECT tags in the HTML but I
would rather have my Flash movie do the work, onBlur and onFocus
don't behave particularly well across different browsers anyway.
Thanks,
Ronny.quick answer - no!
Might be possable from the right click menu, but your down to
the mercy of the way the movie is structured internally. -
Question for REAL ActionScript 3 Gods
Prove you ARE an ActionScript 3 God by solving and exposing here (or in private) a valid way to store classes as SharedObject, and RECOVER THEM LATER AFTER A WEB PAGE RELOADS IN A READY TO USE STATE.
I personally tried everything I know including ByteArray and flash.net functions, but sadly (and very disappointing) I could not do it. I solved many unbelievable things in ActionScript 3 so I guess I can exchange one secret for another if you're not willing to share with the community.
Are there any REAL ActionScript 3 Gods ?Thank you for your answer. I tried but those won't help.
Download: http://www.iflash.ro/various/classToSharedObject.zip
Please take a look at the following (please ignore the incompletness of the code ... listeners missing and possible errors not handled):
Use the first class as document class for a fla at your choice. I named mine 'classToSharedObject.fla'.
package {
import flash.display.Loader;
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.net.SharedObject;
import flash.utils.*;
import flash.net.*;
public class manyKitties extends MovieClip {
public var loader:Loader;
public var object:Object;
public var structure:Class;
public var sharedObject:SharedObject=SharedObject.getLocal('ZCZC','/');
public var passedInfo:Boolean=true;
public function manyKitties() {
if (sharedObject.size>0) {
trace('The SharedObject which holds one system domain class and one runtime class has a size of '+sharedObject.size+' bytes. Is this ok ?!?!');
//sharedObject.data.theClass is declared below in function ripClass
//fail
for (var prop in sharedObject.data.theClass) {
trace(prop);
//fail
trace(sharedObject.data.theClass as Class);
//fail
//object=new structure(passedInfo);
//txt is a TextField on the stage
//txt.text=new structure(passedInfo).aProperty;
} else {
sharedObject.clear();
loader=new Loader ;
loader.load(new URLRequest('runtimeStructure.swf'));
loader.contentLoaderInfo.addEventListener('complete',ripClass);
public function ripClass(e) {
try {
structure=loader.contentLoaderInfo.applicationDomain.getDefinition('ripMe') as Class;
object=new structure(passedInfo);
//aProperty is a public string in runtimeStructure.swf: 'The quick brown fox jumps over the lazy dog'
txt.text=object.aProperty;
//as can be seen, the class is loaded and used correctly
//now I will try to store the runtime class locally
//this is just the easiest example. I tried many versions, including
//ByteArray and registerClassAlias but I failed
// ... maybe I'm too focused and I can't see the obvious
sharedObject.data.theClass=structure;
//Why not store also a system domain class ? Let's store this also
var systemDomainClass:Class=getDefinitionByName("flash.display.MovieClip") as Class;
sharedObject.data.disc=systemDomainClass;
//Maybe we just can't store directly Classes. ByteArray should work
//two byte arrays, one with a runtime class, one with a system domain class
var ba1:ByteArray=new ByteArray ;
ba1.writeObject(structure);
sharedObject.data.BA1=ba1;
var ba2:ByteArray=new ByteArray ;
ba2.writeObject(systemDomainClass);
sharedObject.data.BA2=ba2;
sharedObject.flush();
} catch (e:Error) {
This is where I try to use classes stored locally. Below is a basic runtime class (use it as document class for 'runtimeStructure.fla').
package {
import flash.display.MovieClip;
public class ripMe extends MovieClip {
public var aProperty:String = 'OMG! Many Kitties';
public function ripMe(youPassMeSomeInfo:Boolean = false) {
if (youPassMeSomeInfo) aProperty = 'The quick brown fox jumps over the lazy dog';
//txt is a TextField on the stage
txt.text = aProperty;
As is expected, the first time it runs, classToSharedObjectswf will show a TextField with 'The quick brown fox jumps over the lazy dog' as content.
The second time is run will display as text: 'IF YOU SEE THIS TEXT THE SECOND TIME THE SWF RUNS, MEANS THAT WE FAILED AND WE HAVE TO TRY SOMETHING ELSE.'
If you test in the authoring environment you will be able to see also the trace actions.
Any ideas, suggestions?!
I will come back later with a more complex failed try (too tired now).
Download: http://www.iflash.ro/various/classToSharedObject.zip
P.S. I made a lot of copy and paste here and I see the code it's not shown correctly so please use the archived files for test (scan first ... you never know). -
Customizing ActionScript - Java serialization?
Hi,
I wonder how to customize what ActionScript class is serialized to what Java object, overriding BlazeDS's defaults.
I have a Java class where I would like an ActionScript ArrayCollection to serialize to a custom class.
To illustrate, normally I might have a class on the server like this:
public MyClass {
public void updateRecords(java.util.List[Widget]) {...}
When this is invoked from a remote Flex client, passing an ArrayCollection as the method parameter, BlazeDS serializes that ArrayCollection into a Java List, and everything works fine.
Suppose, however, that I have the above method signature defined in the following way:
public MyClass {
public void updateRecords(MyCustomCollection[Widget]) {... }
In that situation, I'd like to be able to specify a custom serializer that takes an ActionScript ArrayCollection and serializes it into MyCustomCollection. In fact, what I'd really like to do is to use this serializer every time a Java class' interface contains MyCustomCollection.
I looked into flex.messaging.io.TypeMarshaller, but couldn't quite figure out how to use it for that purpose.
Thanks,
-- Frank>
How Java Serialization works internally which algorithm it uses to serialize/deserailaize the objects?
>
See the Java Object Serialization Specification
http://docs.oracle.com/javase/6/docs/platform/serialization/spec/protocol.html
And are you aware that you have never marked a single one of your 119 previous questions as answered?
Total Questions: 119 (119 unresolved)
Are all of those questions really unanswered? Or have you just forgotten to mark them ANSWERED.
Please begin revisiting your large number of previous posts and marking them ANSWERED as appropriate. This is important for several reasons. First because forum volunteers need to focus on unanswered questions - it wastes their time to read thru threads and respond to posts that have actually already been answered since the original poster isn't even going to pay attention to any new replies. That time could have been better spent helping users that have REAL unanswered questions on the forum.
Second, when someone like yourself has large numbers of unanswered questions it basically sends a signal to the volunteers that the person posting the question may not even be reading or responding to the replies the volunteers may make. This leads some volunteers to decide to not even bother responding - why should they spend their time trying to help someone who won't even acknowledge the help that they get?
Third, other people that have the same problem you had find your posts but never see them answered. So they never know if the information provided by the volunteers solved your problem or not. When you mark your questions answered it helps others with the same problem.
Thanks. -
Newbie having difficulty centering images in browser using ActionScript 3.0
I'm a newbie using flex builder 3. I'm learning
ActionScript3.0. After running the AS code from the book, my images
are never in the center of the browser(IE7). After running the
following code (which is supposed to produce a yellow arrow, in the
center of the stage, that rotates to the mouse), I get all the
desired results except the arrow is positioned in the bottom right
corner of my browser and only part of the arrow is visible. if
anyone can suggest a solution it would be highly appreciated.
Please keep in mind that I am a COMPLETE newbie to ActionScript,
Flex Builder 3, and the Flash environments. Thanks in advance.on mouseup or click, if the mouse is down, you can use:
stage.focus=outputText;
if the mouse isn't down, you can don't need a listener to trigger the above. -
Actionscript - How to keep the weight down
When creating banner ads, the weight is always an issue. One easy way to loose a few kb is to decrease the quality of any images in the ad. But how about your code? How does one efficiently slenderize Actionscript? Take a library such as TweenLite for instance, it consists of files above at least 60kb, but it only adds less than 5kb to your swf. Then again, I have written pieces of considerably lighter code, which in the end has added a lot more than 5kb to my swf.
What adds to the weight, and what does not? What should you try to avoid when weight is a problem?
Thanks!Hi.
Well, that's a hard one..It's a balance of ..well everything..
Visually pleasing, smooth execution etc.....
There are times, when the size does not matter..It's all
in the eyes of the beholder.
Reduce image resolution and number of colors
Externally load media when possible..
import only what you need.
Reuse created objects when possible.
Just to name a few...
Nowadays, the size is less of a concern due to faster connections.
Whether your swf file is 200 kb , 800 kb or higher is not what should
be your primary focus..The end product is.
Best of luck -
Hey,
I want to learn Actionscript 3.0 because I have discovered
that you can't do really nice flash stuff without knowing it. I
have Flash CS3. I have no programming or language experience, I
just know a little bit of HTML. What's the best way for me to go
about learning actionscript?
Thanks,eagledrc,
> I want to learn Actionscript 3.0 because I have
discovered
> that you can't do really nice flash stuff without
knowing it.
AS3 is a tremendous, significant re-thinking and
re-organization of the
language. It's an improvement in terms of clarity,
cohesiveness, and
performace. In fact, at the risk of sounding like one of
those late night
plus-if-you-act-now commericials, I can honestly say that the
more I use
AS3, the more I appreciate it.
That said, it's only fair -- to ActionScript and you! -- to
mention that
TONS of cool stuff can be done without ActionScript 3.0. For
years now,
people have been using pre-AS3 Flash to develop MP3 players,
video players,
scrolling platform games (like Mario Bros), multi-user games,
particle
effects, ebooks, interactive multimedia presentations,
slideshows, and the
list goes on. In many ways, the structure of AS3 makes it
easier to work
with, but in terms of actual features, I'll venture to say
that only
complex, advanced projects are likely to benefit from the
speed increases.
So ultimately, you have a choice. Many ad agencies and
development
houses are still publishing to Flash Player 7, just because
the probability
is a tad higher that a consumer has Flash Player 7 over 9. If
you can
publish for Flash Player 9, I'd say take the plunge and go
with ActionScript
3.0. I really think it makes more sense to newcomers than
ActionScript 2.0
as a new language. But all the same, keep a back burner open
for AS2,
because you're likely to run into files written in that
version of the
language for years to come.
> I have Flash CS3. I have no programming or language
experience,
> I just know a little bit of HTML. What's the best way
for me to go
> about learning actionscript?
If it's any encouragement, I didn't have any programming
experience when
I started out either. I came to Flash because I loved (and
still love)
multimedia. I've been fortunate enough to make a career out
of (mostly)
Flash, and the ability to program has certainly made that
easier, as well as
more creatively rewarding. If I could go back to an earlier
me and give
myself advice, I would steer me toward something called
object-oriented
programming (OOP). Even if that younger me didn't want to
become a
caffeine-addicted hardcore programmer, I would insist to
myself that
*thinking in terms of OOP* can help a developer make sense of
the gargantuan
document called the ActionScript 3.0 Language and Components
Reference that
lurks behind the F1 key.
In the tiniest of nutshells, it can be put like this: the
building
blocks of ActionScript -- all the things you deal with, like
movie clips,
text fields, sounds, buttons, and so on -- are called
objects. Objects are
defined by something called classes, which are essentially
blueprints for
the objects they describe. Generally speaking, classes
feature one or more
of the following categories: properties (characteristics of
the object),
methods (things the object can do), and events (things the
object can react
to). Look for those headings when you flip through the
documentation. If
you're dealing with a movie clip, for example, look up the
MovieClip class
and see what features are available to you. Bear in mind that
classes are
organized into family trees -- they inherit functionality
from ancestors --
so make sure to click the "Show Inherited Public
Properties/Methods/Events"
hyperlink you'll find in each class entry. Without that, you
won't get the
full picture.
Even if you don't write your own custom classes, you'll find
that
thinking in terms of a programmer -- thinking in terms of OOP
-- will help
you navigate the documentation.
As far as books, I tend to like "Object-Oriented
ActionScript 3.0"
(friends of ED), by Todd Yard, Peter Elst, and Sas Jacobs.
This one is
geared toward programming and doesn't focus much on the Flash
drawing tools.
http://www.amazon.com/Object-Oriented-ActionScript-3-0-Todd-Yard/dp/1590598458/
You may also get something out of "Foundation Flash CS3 for
Designers"
(friends of ED), which I wrote with my friend Tom Green.
http://www.amazon.com/Foundation-Flash-CS3-Designers/dp/159059861X/
Ours aims at striking a balance between programming and
non-programming
concepts. That doesn't make it better or worse reading
material -- just
gives it a different focus.
I'm also a fan of Colin Moock's work (usually O'Reilly
books), which
tends to be extremely thorough, so take a gander at all of
the above and
read the reviews to see which one(s) may speak to your
personal taste. Good
luck with it!
David Stiller
Contributor, How to Cheat in Flash CS3
http://tinyurl.com/2cp6na
"Luck is the residue of good design." -
Stage.focus doesn't show cursor in TextField?
stage.focus = txt; // txt is a text input field
It successfully gives the TextField "txt" focus because when
I type, the characters appear in the input textfield, however the
familiar blinking text cursor/beam does not appear in the
textfield. This makes you think it does not have focus, so you
click the textfield to give it focus -- completely defeating the
purpose. What's the deal?Doing some searches online I found myself asking this
question over at asctionscript.org over a year ago. :)
http://www.actionscript.org/forums/showthread.php3?t=143111
No one figured it out back then but I revived the thread and
I think someone identified the issue:
The SWF must have system focus for the blinking text
cursor/carat to appear.
In the browser, SWFs do not have focus until you click on it,
or force focus using javascript's focus() function.
What I don't understand is why the Flash Player in the IDE
doesn't start out with focus -- it seems to start out with a sort
of half-focus.
The project I'm working now is in AIR, though. Again, it's
surprising that the AIR SWF doesn't start out with focus, but I
also have no idea how to programatically give the SWF focus from
AIR.
Maybe you are looking for
-
Problems to find bapi to insert itens and services ME32K
Hi Guys, I need insert itens and services on ME32K transaction. I run this using the call transaction method. But, I have problems with this because the program delay very much to run. It load the data, however, delay very much. I am finding a bapi t
-
New to Flash -- tutorial help pls!
Hi: Working with the Flash Developer Center tutorial http://www.adobe.com/devnet/flash/articles/atv_flcs4_demos.html I have Flash CS3 professional, and downloaded a couple of the zip sample files, fla. However, an error message says "Unexpected File
-
RESTORE iPAD FROM SPECIFIC BACKUP
Hi guys, I am currently running 4.2.1. WIth the hype of the new 4.2.1, I synched my iPad quite a few times. As a result, many backups were created. The problem is, I deleted a VERY important Note just after my first backup. I tried to restore the iPa
-
I've googled this problem with no solution. When I select any variation of the Render Audio/All commands, the progress bar flickers on screen at 0% then closes. The audio remains unrendered as does the red bar above it. I cannot render any audio rega
-
Dear All, In our projects business scenario, we have order creation for both parts excisable & non excisable where excise invoice is only to be generated for the parts which are excisable. Both will be entered in single order & we split it into two d