The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Page 25 of 45 FirstFirst ... 15232425262735 ... LastLast
Results 361 to 375 of 669

Thread: ActionScript 3 Tip of the Day

  1. #361

    Fla Script No _lockroot

    ActionScript 3 no longer uses the _lockroot property. The _lockroot property was introduced in Flash Player 7 and allowed _root references in loaded movies to continue to reference the loaded movie's _root instead of the _root of the movie which loaded in that movie if the movie was loaded into a MovieClip.

    In ActionScript 3, all references to root remain connected to the original root of the file as though _lockroot was already in place.

  2. #362

    Fla Script Flash CS3: Automatic Timeline Declarations

    When you write custom classes for your Flash documents (Document classes) or movie clip symbols, normally you would need to declare all movie clip (or other child instances) within the class definition. For example, if you are writing a class for a movie clip which contains another movie clip with the instance name "foo", in the class definition you would have to declare foo.
    Code:
    // within class body:
    public var foo:MovieClip;
    With ActionScript 3 in Flash CS3, you have the option to have Flash make those declarations automatically. To do this check the "Automatically declare stage instances" option in File > Publish Settings > Flash tab > (ActionScript 3) Settings. With that checked, declarations will be done automagically.

    Note: If you do not have that option checked and you do not declare your variables you may get an error that looks like:
    Code:
    ReferenceError: Error #1056: Cannot create property [instanceName] on [Class].
    	at flash.display::Sprite/flash.display:Sprite::constructChildren()
    	at flash.display::Sprite$iinit()
    	at flash.display::MovieClip$iinit()
    	at [Class]$iinit()
    If you have that option checked and you still declare your variables, you may get an error like:
    Code:
    1151: A conflict exists with definition [instanceName] in namespace internal.

  3. #363

    Fla Script Property Access and Downcasting (parent, root, etc.)

    When type is assigned to some properties in ActionScript, it's recognized that values of that property may be of different types or be instances of different classes. That property, however, may require that whatever value is used be at least a subclass of a certain type if not that type directly and therefore isn't typed as having no type (*). An example of such a property is the parent property in Display Objects (root is another popular case). The parent property in the DisplayObject definition is typed as DisplayObjectContainer. This is the required type for any DisplayObject to contian other DisplayObject instances (and thus becoming their parent). But you'll never find a direct instance of DisplayObjectContainer as a parent of another DisplayObject; you'll only have subclasses like Sprite, or MovieClip, or maybe some custom class. Since they extend the DisplayObjectContainer class the DisplayObjectContainer type remains valid for the parent property.

    Here is where a complication exists. As the type DisplayObjectContainer, Flash will only expect properties of the DisplayObjectContainer class to be used with the parent reference. If you attempt to use a non-DisplayObjectContainer property from a parent reference - and this can be a valid property that actually exists in that parent - you will get an error because that property is not recognized in DisplayObjectContainer, the type associated with the parent property. The error will look something like

    Code:
    Error 1119: Access of possibly undefined property <property> through a reference with static type flash.display:DisplayObjectContainer.
    To get around this error you need to assign the parent reference to a new variable with the type needed downcasting the parent to that type. Before doing this, its always a good idea to make sure the parent is actually the type you are casting to.

    Code:
    // assuming parent is really of type MovieClip
    // parent.gotoAndStop(1); // Error; call to undefined method
    
    // it's always a good idea to make
    // sure parent really is of the correct type
    if (parent is MovieClip) {
    
    	// downcast parent to MovieClip assinging
    	// it to a new variable
    	var par:MovieClip = MovieClip(parent); // or: parent as MovieClip;
    	par.gotoAndStop(1); // works
    }
    Note: for quicker access to a single property when you're sure of the property type, you can just use something like the following:
    Code:
    MovieClip(parent).gotoAndStop(1);

  4. #364
    I've updated the first post with some samples links:


    Samples:
    Flex 2 AS3 Samples
    Flash CS3 Samples

  5. #365

    Fla Script Loading a Cross-domain Policy File

    Cross-domain policy files (crossdomain.xml) are used by the Flash player to let a web server allow or disallow data to be used in Flash by another domain. ActionScript 3 lets you specify if you want to load and check a cross-domain policy file when you load content from another server (rather than just checking it automatically as was the case with ActionScript 2). This is handled within a LoaderContext (flash.system.LoaderContext) instance.

    By default, policy files are not checked; this saves loading time and bandwidth. To assure that Flash checks the necessary policy file when loading content, you would create a new LoaderContext instance, set its checkPolicyFile property (LoaderContext.checkPolicyFile) to true, and pass that instance into your call to load.

    Code:
    // create a loader context that
    // checks for policy files
    var context:LoaderContext = new LoaderContext();
    context.checkPolicyFile = true;
    
    // use the context with your call to load
    myLoader.load(request, context);

  6. #366

    Fla Script Loading External Classes with ApplicationDomain

    When you load an external ActionScript 3 SWF into a Loader instance in another ActionScript 3 SWF you can have the loaded SWFs definitions be shared with the SWF handling the loading or you can have it completely separated. The location of these definitions is known as the Application Domain.

    In ActionScript 3 there is a hierarchy of application domains that describes class relations. You can have application domains separated (thereby keeping definitions separated) or you can an application domain as the child of another application domain. A child application domain will use definitions in its parents' application domains before it uses its own if they are defined in a parent.

    When loading a SWF into another SWF you have 3 options for the placement of the loaded SWFs definitions:
    • new partitioned domain: create a new separated domain for the loaded SWFs definitions to live that will separate it completely from those definitions within the loading SWF.
    • current domain: load the definitions into the current application domain of the loading SWF. This will not overwrite existing definitions but it will add new definitions to those within the current application domain of the SWF doing the loading.
    • child domain (default): load the definitions into a new application domain that is a child of the application domain of the loading SWF. This will not affect the current application domain of the loading SWF but it will force the loaded SWF to use any duplicate definitions in the parent over its own


    You specify application domains for loaded content within a LoaderContext (flash.system.LoaderContext) instance. This instance is then passed to the load() method of Loader (Loader.load()). For the domain of the current SWF, you can use ApplicationDomain.currentDomain ().

    Code:
    // child SWF uses parent domain definitions
    // if defined there, otherwise its own
    var childDefinitions:LoaderContext = new LoaderContext();
    childDefinitions.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
    
    // child SWF adds its unique definitions to
    // parent SWF; both SWFs share the same domain
    // child SWFs definitions do not overwrite parents
    var addedDefinitions:LoaderContext = new LoaderContext();
    addedDefinitions.applicationDomain = ApplicationDomain.currentDomain;
    
    // child SWF domain is completely separate and
    // each SWF uses its own definitions
    var separateDefinitions:LoaderContext = new LoaderContext();
    separateDefinitions.applicationDomain = new ApplicationDomain();
    
    // set loader context in load()
    myLoader.load(request, separateDefinitions);
    More information:

  7. #367

    Fla Script Save Memory When Reusing Bitmaps With the Same BitmapData

    Each Bitmap instance in ActionScript 3 references a separate BitmapData instance as a source for its graphics data. When you have two Bitmap instances, you potentially have 2 separate BitmapData instances as well.

    If you want to have two Bitmaps that look exactly the same, you can save memory by making both of those bitmaps reference the same BitmapData instance through ActionScript. All you need to do is create the second Bitmap using the BitmapData from the original. Any changes made to the BitmapData instance will affect both Bitmaps on screen.

    Code:
    // copyBitmap will appear as a copy of 
    // the originalBitmap Bitmap instance
    var copyBitmap:Bitmap = new Bitmap(originalBitmap.bitmapData);

  8. #368

    Fla Script ActionScript SWFs and Version Compatibility

    Because ActionScript 3 uses a completely new AVM (ActionScript Virtual Machine) than ActionScript 1 and ActionScript 2, there is limited compatibility between movies created with these different versions of ActionScript. The short of it is this, where AVM1 represents ActionScript 1 and ActionScript 2 movies and AVM2 represents ActionScript 3 movies:
    • AVM1 cannot load AVM2
    • AVM2 can load AVM2 or AVM1 (but)
    • AVM2 can only interact with AS in AVM1 using LocalConnection

    Essentially, your ActionScript 1 and 2 movies are not going to be able to interact with ActionScript 3 movies without some work, and it requires that an AS3 movie be used to load in the AS1 or AS2 movie(s).

    For more information, read:

  9. #369
    Quote Originally Posted by senocular View Post
    ...This should be used in place of TextField.text += newText since appendText is faster and more efficient.

    ActionScript Code:
    my_tf.appendText(" world!"); // my_tf.text == "Hello world!"



    That given, what would be the best practice if you want to append HTML text? There doesn't appear to be a similar speedup for HTML, so we're stuck with += - is that correct?

    Ooh, also, I'd love to see a tip about making the most of the new debugger. There is much to learn about that beast, since List Variables is now all but empty.
    Last edited by dthought; May 12th, 2007 at 10:54 PM.

  10. #370
    isn't htmltext just a string

    same should apply

  11. #371
    Quote Originally Posted by dthought View Post
    That given, what would be the best practice if you want to append HTML text?
    There isn't an equivalent for HTML text.

  12. #372
    Quote Originally Posted by Dazzer View Post
    isn't htmltext just a string

    same should apply
    No no... in AS3.0, the TextField still has both its text and htmlText properties and you can append strings for both using +=.

    However, there is a new method applying to text only - appendText(); which is a signficiant speedup over using +=... however, there is no equivalent for htmlText, so if your textbox contains HTML you have to use the "slower" alternative (which is still quick enough, as it has always been )

  13. #373
    the example in #365 is

    // create a loader context that
    // checks for policy files
    var context:LoaderContext = new LoaderContext();
    childDefinitions.checkPolicyFile = true;

    // use the context with your call to load
    myLoader.load(request, context);


    why not

    context.checkPolicyFile = true;



    what's childDefinitions ??

  14. #374
    Quote Originally Posted by nshen121 View Post
    the example in #365 is

    // create a loader context that
    // checks for policy files
    var context:LoaderContext = new LoaderContext();
    childDefinitions.checkPolicyFile = true;

    // use the context with your call to load
    myLoader.load(request, context);


    why not

    context.checkPolicyFile = true;



    what's childDefinitions ??
    nshen121, thats a typo. I'll fix it now

  15. #375

    Afrostyle

    I am getting this error:

    Error #1006: invalidate is not a function.

    This is frustrating because there are so many new things going on. Everytime I write a block of code I get some silly error. Can someone help?

Page 25 of 45 FirstFirst ... 15232425262735 ... LastLast

Thread Information

Users Browsing this Thread

There are currently 4 users browsing this thread. (0 members and 4 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012