Go Back   kirupaForum > Flash > ActionScript 3.0

Reply
 
Thread Tools Display Modes
Old 05-13-2008, 12:57 PM   #511
lestat2411
Registered User
Loading Multiple as2 swfs into as3 player. Example doesnt work.

Quote:
Originally Posted by senocular View Post
The ActionScript virtual machine that runs ActionScript 3 code (AVM2) is completely different from the ActionScript virtual machin that runs ActionScript 1 and ActionScript 2 code (AVM1). Because of this, you cannot call commands in an AVM1 movie from and AVM2 movie or vise versa. The virtual machines just are not compatible in that respect and mostly run in their own kind of shell that allows it to only interact with code being played back in that same virtual machine. What that boils down to is that ActionScript 3 cannot talk to AS1 or AS2 - at least not directly.

One thing these two virtual machines have in common is their implementation of LocalConnection. Both virtual machines deal with local connections in essentially the same way - enough that local connections in AVM1 can receive events from AVM2 and vise versa. So should you come into a situation where you would need a movie published in ActionScript 3 to communicate with a movie published in ActionScript 1 or 2, using local connection is the way to go.

Example:
ActionScript Code:
// ActionScript 2 file, AS2animation.fla
// one movie clip animation named animation_mc on the timeline

// local connection instance to receive events
var AVM_lc:LocalConnection = new LocalConnection();

// stopAnimation event handler
AVM_lc.stopAnimation = function(){
    animation_mc.stop();
}

// listen for events for "AVM2toAVM1"
AVM_lc.connect("AVM2toAVM1");


ActionScript Code:
// ActionScript 3 file, AS3Loader.fla

// local connection instance to communicate to AVM1 movie
var AVM_lc:LocalConnection = new LocalConnection();

// loader loads AVM1 movie
var loader:Loader = new Loader();
loader.load(new URLRequest("AS2animation.swf"));
addChild(loader);

// when AVM1 movie is clicked, call stopPlayback
loader.addEventListener(MouseEvent.CLICK, stopPlayback);

function stopPlayback(event:MouseEvent):void {
    // send stopAnimation event to "AVM2toAVM1" connection
    AVM_lc.send("AVM2toAVM1", "stopAnimation");
}



The AS3 movie loads the AS2 movie into a Loader instance and places it on the screen. As it plays, the user can click the animation which calls stopPlayback sending the "stopAnimation" event to the local connection named "AVM2toAVM1". The AS2 movie is then able to receive that event in its stopAnimation event handler and tell the animation_mc clip to stop.

I am having a problem with as3 talking to as2 after the initial as2 swf is loaded. Using this example, the first swf comes in and can be controlled just fine. However, if I load a second swf into the AS3 player, it no longer can be controlled. So basically what I need to figure out is how to load multiple as2 swfs into a as3 player. We have a bunch of content which was developed in as2 that we do not want to rewrite at this time. Is there a way to accomplish this.

P.S. The weirdest thing is I put a trace statement in the first as2 swf and after I have unload this clip and loaded the next as2 swf, the trace from the original swf can still be called meaning I believe its removed from the display list but not out of memory. Any clues would be greatly appreciated. I am playing around with gskinner swfbridge right now but haven't found a solution using this either. Thanks in Advance.

Stat
lestat2411 is offline   Reply With Quote

Sponsored Links (Guests Only) - Register | Need Help?
 

Old 05-14-2008, 03:40 AM   #512
coolheart
Registered User
How to insert text in to that swf file

If my swf file contains a textbox, on some background, how to insert a text message like hello into that text box.



Quote:
Originally Posted by senocular View Post
You can pass variables to SWF files in the object/embed code used to display a SWF in HTML. You can do this two ways, one using URL variables (query string) at the end of the SWF path, or through the FlashVars property.
HTML Code:
<!-- URL Variables -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="640" height="500" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="flashMovie.swf?myVar=1" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#EFF7F6" />
    <embed src="flashMovie.swf?myVar=1" quality="high" bgcolor="#EFF7F6" width="640" height="500" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
HTML Code:
<!-- FlashVars -->
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="550" height="400" align="middle">
    <param name="allowScriptAccess" value="sameDomain" />
    <param name="movie" value="flashMovie.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#FFFFFF" />
    <param name="FlashVars" value="myVar=1" />    
    <embed src="flashMovie.swf" FlashVars="myVar=1" quality="high" bgcolor="#FFFFFF" width="550" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
In ActionScript 2, these variables were simply defined as variables in _root. This has changed for ActionScript 3. Now these variables are accessible in a parameters object located in the root loaderInfo object.

Given the HTML embed code above, you would access the myVar property using:
ActionScript Code:
root.loaderInfo.parameters.myVar;
coolheart is offline   Reply With Quote
Old 05-14-2008, 06:21 AM   #513
log2e
OOP Addict
 
log2e's Avatar
Quick Tip - Where are my Easing Equations?

Easing Functions in Flash CS3 / Flex 3 SDK

Tutorials on TweenLite or TweenMax often rely on the easing functions that come with the Flash CS3 IDE. These functions are contained in the package fl.motion.easing. All classes under the package name fl are specific to Flash CS3 and are not available in the free Flex 3 SDK. If you use the Flex 3 SDK you have to import your easing functions from the package mx.effects.easing. So any time you see an import statement like this

import fl.motion.easing.*;

you should be able to replace it with

import mx.effects.easing.*;

and get the same functionality.
log2e is offline   Reply With Quote
Old 05-20-2008, 10:45 AM   #514
kBisk
Laser 187414
 
kBisk's Avatar
Quote:
Originally Posted by senocular View Post
In previous versions of ActionScript, there were a couple of classes who had the capability of loading external text, namely LoadVars and XML. The loading responsibilities of these classes has moved to one single class in ActionScript 3, URLLoader (flash.net.URLLoader). This class is a lot like LoadVars. The big difference is that it is used for XML since the responsibility of loading XML from an external source has been removed from the XML class. Instead, you would load the text with URLLoader and then give that text to an XML object for parsing.

Like LoadVars, URLLoader has a load() method that is used to load text from an external source. This accepts 1 argument, a URLRequest instance (NOT a URL string). You can then use events from URLLoader to determine when the loading is complete. When complete, the text loaded is available in the data property of URLLoader.

Example:
ActionScript Code:
var loader:URLLoader;
// ...
loader = new URLLoader();
loader.addEventListener(Event.COMPLETE, xmlLoaded);

var request:URLRequest = new URLRequest("file.xml");
loader.load(request);
//...
function xmlLoaded(event:Event):void {
&nbsp;&nbsp;&nbsp;&nbsp;var myXML:XML = new XML(loader.data);
&nbsp;&nbsp;&nbsp;&nbsp;//...
}
What event on URLLoader catches if the file does not load / does not exist?

Found the answer. Using a try/catch was also an option, but this event also works:
ActionScript Code:
IOErrorEvent.IO_ERROR

__________________


ScriptReaction.com | Multi Media Development by Kevin Biskaborn | London Ontario Canada


Last edited by kBisk; 05-20-2008 at 10:50 AM.. Reason: Found the answer...
kBisk is offline   Reply With Quote
Old 05-27-2008, 08:52 AM   #515
project1.exe
Registered User
URLRequest and URLVariables to a url value

Hi,

I have a "u" and "v" variables and i do this for example...

var u:URLRequest = new URLRequest("www.google.com");
var v:URLVariables = new URLVariables("q=hehe");

u.data = v;

trace(u.url);

how do i get it so it will trace "www.google.com?q=hehe"
project1.exe is offline   Reply With Quote
Old 05-30-2008, 08:31 PM   #516
WestCoast101
Registered User
Thanks for the duplicateMovieClip package... As a relatively new AS3 student, can you direct me to an explanation of the options for the -- var targetClass:Class = Object(target).constructor; -- ? I apprecate that you can not instantiate the DisplayObject class.

In addition, although I have the AS3 Bible for reference, can you suggest other texts? I used Russell Chun's AS3 book effectively this Semester in my AS3 class.
WestCoast101 is offline   Reply With Quote
Old 06-03-2008, 12:22 PM   #517
delfeld
Registered User
Location Nebraska, if you can believe it.

Posts 13
checking for stage's existence

It's a good idea to make sure that the stage exists before working with it:

Code:
if (stage) 
{
  trace("stageWidth: " + stage.stageWidth + " stageHeight: " + stage.stageHeight);
  stage.frameRate = stage.frameRate + 100;
}
delfeld is offline   Reply With Quote
Old 06-04-2008, 01:24 PM   #518
log2e
OOP Addict
 
log2e's Avatar
1, true, yes, y, on? - A Boolean Converter

Configuration files often contain Boolean parameters for enabling or disabling features in an application or website. This way non-programmers can easily customize a complex system. But what if someone uses another word than “true” (for example, “1″, “yes”, “y”, “on”)?

In order to make my Flash/Flex apps less error-prone, I usually run all Boolean values from external configuration files through a converter. It’s a simple class with a single static method:

Code:
package 
{
   public class BooleanConverter
   {
        
      public static const TRUE_VALUES:Array = [ "1", "true", "yes", "y", "on", "enabled" ];
            
      public static function makeBoolean( val:* ):Boolean
      {
         var str:String = String( val ).toLowerCase();
            
         for ( var i:int = 0; i < BooleanConverter.TRUE_VALUES.length; i++ )
         {
            if ( str == BooleanConverter.TRUE_VALUES[i] )
            {
               return true;
            }
         }
         return false;            
      }

   }
}

__________________
www.log2e.com | blog.log2e.com
Everybody else is just green.

Last edited by log2e; 06-04-2008 at 02:14 PM..
log2e is offline   Reply With Quote
Old 06-07-2008, 01:18 AM   #519
Keyston
Registered User
Quote:
Originally Posted by log2e View Post
Configuration files often contain Boolean parameters for enabling or disabling features in an application or website. This way non-programmers can easily customize a complex system. But what if someone uses another word than “true” (for example, “1″, “yes”, “y”, “on”)?

In order to make my Flash/Flex apps less error-prone, I usually run all Boolean values from external configuration files through a converter. It’s a simple class with a single static method:

Code:
package 
{
   public class BooleanConverter
   {
        
      public static const TRUE_VALUES:Array = [ "1", "true", "yes", "y", "on", "enabled" ];
            
      public static function makeBoolean( val:* ):Boolean
      {
         var str:String = String( val ).toLowerCase();
            
         for ( var i:int = 0; i < BooleanConverter.TRUE_VALUES.length; i++ )
         {
            if ( str == BooleanConverter.TRUE_VALUES[i] )
            {
               return true;
            }
         }
         return false;            
      }

   }
}
Code:
package 
{
   public class BooleanConverter
   {
        
      public static const TRUE_VALUES:Array = [ "1", "true", "yes", "y", "on", "enabled" ];
            
      public static function makeBoolean( val:* ):Boolean
      {
         var str:String = String( val ).toLowerCase();
            
        return (BooleanConverter.TRUE_VALUES.indexOf(str)!=-1)?true:false;
   
      }

   }
}
Thought i would post an optimized version
Keyston is offline   Reply With Quote
Old 06-09-2008, 06:34 PM   #520
NickZA
Registered User
 
NickZA's Avatar
Utilising static methods in a derived class

Hi

I'm currently trying to use a faux-abstract Singleton class to derive a couple of subclasses from.

The Singleton method I'm using is one of the many which uses a static function getInstance() to return the static var holding the singleton instance.

But it seems I'm unable to use getInstance() in the derived classes. I read elsewhere that "static methods and variables don’t exist within the inheritance chain of the class in AS3".

Is this why I cannot use getInstance() in the derived class? Is there a workaround?

Thanks.

-Nick


Quote:
Originally Posted by senocular View Post
Overriding a method of a class means redefining a method for a class which would otherwise be inherited. The new method is then used in place of the inherited one (though the inherited method can still be invoked using super).

For ActionScript 3, when you override a method or property of a superclass, you need to use the override attribute with your new method. This specifies that the member you are creating is overriding that which would otherwise be inherited. If you do not use override with a method that already exists in a superclass, an error is thrown at compile time.

Ex:
ActionScript Code:
package {
&nbsp;&nbsp;&nbsp;&nbsp;import flash.display.*;
&nbsp;&nbsp;&nbsp;&nbsp;class MySprite extends Sprite {

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pr ivate var children:Array = new Array();

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pu blic function MySprite() {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;}

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pu blic override function addChild(childisplayObject)isplayObject {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;children.push(child);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;super.addChild(child);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;return child;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;}
&nbsp;&nbsp;&nbsp;&nbsp;}
}


Since addChild exists in the Sprite superclass, the override attribute is needed to successfully define the new addChild method which also adds the child passed to a children array.

Note that the method signature needs to match that of the overriden method

Override works with both normal class methods as well as getter/setter methods (properties), but it will not work with any of the following:
  • Variables
  • Constants
  • Static methods
  • Methods that are not inherited
  • Methods that implement an interface method
  • Inherited methods that are marked as final in the superclass

Also be aware that override is not needed for methods inherited directly from the Object class. These include:
  • hasOwnProperty
  • isPrototypeOf
  • propertyIsEnumerable
  • setPropertyIsEnumerable
  • toString
  • valueOf
These methods are added dynamically and are not part of the actual class definition. The override keyword is to be used only with methods which are part of a class's original definition.

However, if extending a class which uses a method above as part of its defnition, the override keyword is required. For example, if you are extending Object, you do not need to use the override keyword for the toString method. But, if you extend the Sprite class, you will need to override toString since the Sprite class has its own unique toString which is part of its class definition.

__________________
www.visualharmonics.co.uk
NickZA is offline   Reply With Quote
Old 06-09-2008, 06:38 PM   #521
Krilnon
≈ ≠ =
 
Krilnon's Avatar
Location Rochester, NY

Posts 7,183
Quote:
Is this why I cannot use getInstance() in the derived class?
Yes.

Quote:
Is there a workaround?
Yes, just define a new version of getInstance on your subclasses.
Krilnon is offline   Reply With Quote
Old 06-09-2008, 06:43 PM   #522
NickZA
Registered User
 
NickZA's Avatar
Damnit that was the fastest response I've ever seen. I was about to go to bed because of this problem, but now...

Thanks Krilnon!

Quote:
Originally Posted by Krilnon View Post
Yes.



Yes, just define a new version of getInstance on your subclasses.

__________________
www.visualharmonics.co.uk
NickZA is offline   Reply With Quote
Old 06-10-2008, 12:06 PM   #523
delfeld
Registered User
Location Nebraska, if you can believe it.

Posts 13
more options for SWF metadata tag

The [SWF] metadata tag for AS3.0 has these params:

[SWF
width="#"
height="#"
widthPercent="#"
heightPercent="#"
scriptRecursionLimit="#"
scriptTimeLimit="#"
frameRate="#"
backgroundColor="#"
pageTitle="<String>"
]

Please see the comment at the bottom of this page:

http://livedocs.adobe.com/flex/3/htm...etadata_3.html
delfeld is offline   Reply With Quote
Old 06-17-2008, 03:17 PM   #524
NickZA
Registered User
 
NickZA's Avatar
How to pass params with Document Class?

Hi

Is there any way to pass arguments into the document class? I'm guessing no?

-Nick

__________________
www.visualharmonics.co.uk
NickZA is offline   Reply With Quote
Old 06-19-2008, 10:34 AM   #525
johnlouis
Blast off!
 
johnlouis's Avatar
Location Cebu, Philippines

Posts 495
Quote:
Originally Posted by senocular View Post
ActionScript 3 no longer has a duplicateMovieClip method for MovieClip instances (or any DisplayObject instances). Instead, it's suggested that you just create a new instance of the display object you wish to duplicate using its constructor. This, however, is not the same as duplicateMovieClip, and, really, is more like using AS1 and AS2's attachMovieClip. For a more accurate representation of duplicateMovieClip in AS3, consider the following function:
ActionScript Code:
package com.senocular.display {
   
    import flash.display.DisplayObject;
    import flash.geom.Rectangle;
   
    /**
     * duplicateDisplayObject
     * creates a duplicate of the DisplayObject passed.
     * similar to duplicateMovieClip in AVM1
     * @param target the display object to duplicate
     * @param autoAdd if true, adds the duplicate to the display list
     * in which target was located
     * @return a duplicate instance of target
     */

    public function duplicateDisplayObject(target:DisplayObject, autoAdd:Boolean = false):DisplayObject {
        // create duplicate
        var targetClass:Class = Object(target).constructor;
        var duplicate:DisplayObject = new targetClass();
       
        // duplicate properties
        duplicate.transform = target.transform;
        duplicate.filters = target.filters;
        duplicate.cacheAsBitmap = target.cacheAsBitmap;
        duplicate.opaqueBackground = target.opaqueBackground;
        if (target.scale9Grid) {
            var rect:Rectangle = target.scale9Grid;
            // WAS Flash 9 bug where returned scale9Grid is 20x larger than assigned
            // rect.x /= 20, rect.y /= 20, rect.width /= 20, rect.height /= 20;
            duplicate.scale9Grid = rect;
        }
       
        // add to target parent's display list
        // if autoAdd was provided as true
        if (autoAdd && target.parent) {
            target.parent.addChild(duplicate);
        }
        return duplicate;
    }
}

As you can see, this function (duplicateDisplayObject) takes care of making sure a duplicated instance also retains all the information retained by duplicateMovieClip such as transformation, filters, chaching as bitmap, etc.

Note: There is currently a bug in Flash Player 9 that causes incorrect values to be returned from the scale9Grid property of display objects. This function compensates for that but may need to be edited should this bug be fixed.

Usage:
ActionScript Code:
import com.senocular.display.duplicateDisplayObject;

// create duplicate and assign to newInstance variable
// using true for autoAdd automatically adds the newInstance
// into the display list where myOldSprite is located
var newInstance:Sprite = duplicateDisplayObject(myOldSprite, true);
newInstance.x += 100; // shift to see duplicate
 


The only thing duplicateMovieClip does that this does not is copy dynamic drawing information. Currently, the graphics object in display objects cannot be duplicated so there is no way to obtain that information for duplicates in duplicateDisplayObject.
i'm having problems with this method.. i have a movieclip I created on the stage, and I tried using this function on it, but I don't see any duplicated movieclip..
the code is on the timeline..
ActionScript Code:
var temp:MovieClip = duplicateDisplayObject(mc, true) as MovieClip;
temp.x += 100;

I also tried duplicating a dynamically drawn Sprite (through graphics property), and like what the quote above said, i don't see anything..

__________________
blog
help me with my site?
johnlouis is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 30 (1 members and 29 guests)
kagamushu
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:12 PM.

SUPPORTERS:

kirupa.com's fast and reliable hosting provided by Media Temple. flash components
Creative web apps. Make your own free flash banners and photo slideshows.
Check out the great, high-quality flash extensions. Buy or sell stock flash, video, audio and fonts for as little as 50 cents at FlashDen.

Flash Transition Effects

Flash Effect Tutorials

Digicrafts Components
Flash effects. Art without coding. Upload, publish, deliver. Secure hosting for your professional or academic video, presentations & more. Screencast.com
Streamsolutions Content Delivery Networks Flipping Book - page flip flash component.
Flash-Gallery.com - Get your flash photo gallery (flash component or swf gallery Learn how to advertise on kirupa.com
 

cdn
content delivery network (cdn)

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd. Copyright 2010 - kirupa.com Copyright 2010 - kirupa.com