Author Topic: action script interactions between pages  (Read 3299 times)

stopwind

  • Newbie
  • *
  • Posts: 7
action script interactions between pages
« on: October 22, 2009, 12:39:33 am »
Hi all! I'm new to Megazine 3. Now I am trying to create some interactions between separated pages, for example:

Put some buttons on the Left page, and when you press a button, the image on the Right page will be changed.

Currently I'm using v1.38, and followed the tutorial to get the swf by ID:

var element:AbstractElement = mz.getElementById("newTrend_R").element;
var swf:DisplayObject = element.swf;

However, I got compilation error "Access of possibly undefined property swf..."
Does anyone got this problem too? Thanks a lot in advance!

Another question is if I put some movie clips on the Right page, can I call something like:

swf.setChildIndex(movieClip_1, topLayer)

when the button on the Left page is pressed to get the effect I mentioned in the example? Thanks again! ;)

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: action script interactions between pages
« Reply #1 on: October 22, 2009, 10:21:34 am »
To get around the compiler warning/error:
Code: (actionscript3)
  1. var element:AbstractElement = mz.getElementById("newTrend_R").element;
  2. var swf:DisplayObject = element["swf"];

Or switch to 2.0 and use the IImg interface ;)

The setChildIndex works on the children of the loaded swf, so if that's what you want, that should be fine. The z-index of actual page elements cannot be changed.

Overall alternative: use 2.0 and make it spreadpage, so you have it all in one swf ;)
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

stopwind

  • Newbie
  • *
  • Posts: 7
Re: action script interactions between pages
« Reply #2 on: October 22, 2009, 09:59:39 pm »
Brilliant! :D I can setup the interaction between swf files!
Thanks a lot!  ;D will definitely try out 2.0  ;D

cduchesne

  • Newbie
  • *
  • Posts: 24
Re: action script interactions between pages
« Reply #3 on: October 26, 2009, 08:19:20 pm »
Has a new tutorial been written for Actionscript Interaction in version 2.0?

I need to pass a variable chosen in a swf from one page to the next. Essentially, it's a story book and the user chooses between a slow or fast version.

Do we use this new IImg interface and if so, how does it get called? The API seems to just list the possibilities, but doesn't explain how to use them.

Or do we keep using getElementById, which now seems to be part of a new plugin elementids?

Or is there another, simpler way to pass variables from one page to the next?

thanks!

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: action script interactions between pages
« Reply #4 on: October 26, 2009, 09:31:37 pm »
You're on the right track with the plugin ;)
I adjusted the original tutorial when moving it to the project wiki, so this one is for v2:
http://megazine.mightypirates.de/wiki/index.php/ActionScript_Interaction
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

cduchesne

  • Newbie
  • *
  • Posts: 24
Re: action script interactions between pages
« Reply #5 on: October 26, 2009, 11:04:38 pm »
thanks for your response!

However, I'm getting errors compiling the flash.

In the tutorial, you mention needing the Image class from elements. I assume you mean Img?

The error: Type IElementIds is not found. Do we need to import de.mightypirates.megazine.plugins.elementids in Flash as well? (or is it rather called as de.mightypirates.megazine.plugins.elementids.IElementIds?)


Here is my code, perhaps I'm missing something?:

import de.mightypirates.utils.events.VisibilityEvent;
import de.mightypirates.megazine.interfaces.*;
import de.mightypirates.megazine.elements.Img;

var mz:IMegaZine;

function megazineSetup(mz:IMegaZine):void{

   var plugin:IElementIds = mz.pluginManager.getPlugin("elementids");
   if (plugin) {
      var proxy:IElementProxy = plugin.getElementById("ChoixVitesse");
      if (proxy.element) {
         // Element is loaded, work with it.
         var element:IElement = proxy.element;
         if (element is Img) {
            var mySwf:DisplayObject = element.swf;
         }
         // Calls function in refered swf to store variable
         choix_vitesse = mySwf.GetCHox();
         startLoad();
      } else {
         // Element not loaded.
      }
   } else {
      // Plugin failed loading.
   }
}

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: action script interactions between pages
« Reply #6 on: October 27, 2009, 08:45:32 pm »
You're right, of course. It should read Img, or rather its interface, IImg. Fixed that.

And yes, you'll have to import the plugin's interface, too:
Code: (actionscript3)
  1. import de.mightypirates.megazine.plugins.elementids.IElementIds
.
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

cduchesne

  • Newbie
  • *
  • Posts: 24
Re: action script interactions between pages
« Reply #7 on: October 27, 2009, 10:19:01 pm »
Now I'm getting the following error compiling Flash:
 Implicit coercion of a value with static type de.mightypirates.megazine.interfaces:IPlugin to a possibly unrelated type de.mightypirates.megazine.plugins.elementids:IElementIds.

i added the import of the plugins.PluginManager (from plugins or is it rather interfaces.IPluginManager?), thinking it might be necessary, but it didn't make a difference.

Do you mind having a look at my code, please?

import de.mightypirates.megazine.interfaces.*;
import de.mightypirates.megazine.elements.Img;
import de.mightypirates.megazine.plugins.elementids.IElementIds;
import de.mightypirates.megazine.plugins.PluginManager;

var mz:IMegaZine;
var mySwf:MovieClip;

function megazineSetup(mz:IMegaZine, ps:IPageSide):void{
   
   var plugin:IElementIds = mz.pluginManager.getPlugin("elementids");
   if (plugin) {
      var proxy:IElementProxy = plugin.getElementById("ChoixVitesse");
      if (proxy.element) {
         // Element is loaded, work with it.
         var element:IElement = proxy.element;
         if (element is IImg) {
            var mySwf:DisplayObject = (element as IImg).swf;
            choix_vitesse = mySwf.GetCHox();
            startLoad(choix_vitesse);
         }
         
      } else {
         // Element not loaded.
      }
   } else {
      // Plugin failed loading.
   }
}

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: action script interactions between pages
« Reply #8 on: October 27, 2009, 10:30:36 pm »
Ah right. You'll have to manually cast it.

change
Code: (actionscript3)
  1. var plugin:IElementIds = mz.pluginManager.getPlugin("elementids");
to
Code: (actionscript3)
  1. var plugin:IElementIds = mz.pluginManager.getPlugin("elementids") as IElementIds;
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

egatuz

  • Newbie
  • *
  • Posts: 10
Re: action script interactions between pages
« Reply #9 on: January 07, 2010, 01:25:37 pm »
i've got this problem too.

let us take a look of the code below:

Code: [Select]
package com.badutgallery{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.events.Event;
import fl.data.DataProvider;
import fl.controls.TileList;
import fl.events.ListEvent;
import de.mightypirates.megazine.interfaces.*;
import de.mightypirates.megazine.plugins.elementids.*;
import de.mightypirates.megazine.elements.AbstractElement;
import de.mightypirates.megazine.elements.Img;
import de.mightypirates.utils.events.VisibilityEvent;

public class TileImage extends Sprite {
private var mz:IMegaZine;
private var pageside:IPageSide;
private var plugin:IElementIds;
private var proxy:IElementProxy;
private var element:IImg;
private var mySwf:DisplayObject;
private var myXML:XML;
private var myXMLList:XMLList;
private var dp:DataProvider;
public var tileList:TileList;
public function TileImage():void {
megazineSetup(mz);
loadXML();
buildTileList();
}
private function megazineSetup(megazine:IMegaZine):void {
mz=megazine;
plugin=mz.pluginManager.getPlugin("elementids") as IElementIds;
if (plugin) {
proxy=plugin.getElementById("mascotViewer");
if (proxy.element) {
element=proxy.element as IImg;
}
}
//element = megazine.getElementById("myElement").element;
if (element is IImg) {
mySwf=element["swf"];
}
}
private function loadXML():void {
var urlRequest:URLRequest=new URLRequest("mascot/mascot.xml");
urlRequest.method=URLRequestMethod.POST;
var urlLoader:URLLoader=new URLLoader  ;
urlLoader.dataFormat=URLLoaderDataFormat.TEXT;
urlLoader.addEventListener(Event.COMPLETE,urlLoaderCompleteHandler);
urlLoader.load(urlRequest);
}
private function urlLoaderCompleteHandler(evt:Event):void {
myXML=new XML(evt.target.data);
myXMLList=new XMLList(myXML.items);
setupDataProvider(myXMLList);
}
private function setupDataProvider(xml:XMLList):void {
dp=new DataProvider(xml);
}
private function buildTileList():void {
tileList=new TileList  ;
tileList.dataProvider=dp;
tileList.addEventListener(ListEvent.ITEM_CLICK,itemClickHandler);
}
private function itemClickHandler(e:ListEvent):void {
mySwf.LoadImage(e.item.big);
}
}
}

and i got this compile errors :
1061: Call to a possibly undefined method LoadImage through a reference with static type flash.display:DisplayObject.

it looks we cannot call the swf's functon(in my code above:mySwf and the function is LoadImage() ) from the class we're being create. ???
« Last Edit: January 07, 2010, 01:33:42 pm by egatuz »

Florian Nücke

  • κρύα πόδια
  • Administrator
  • Hero Member
  • *****
  • Posts: 1985
  • MegaZine3 Developer
    • MegaZine3
Re: action script interactions between pages
« Reply #10 on: January 11, 2010, 02:24:16 pm »
Yeah, you cannot reference that function statically, unless you manually cast the variable to the the class your SWF extends. If it doesn't extend one, you have to reference it dynamically, like so:
Code: [Select]
mySwf["LoadImage"](e.item.big);
For the Snark was a Boojum, you see.

Before you ask a question
          After you get an answer
  • please document your problem with the answer in the Project Wiki. (e.g. in the FAQs)
  • help others out if you can, by answering their questions on the forum.

dark lord

  • Newbie
  • *
  • Posts: 1
Re: action script interactions between pages
« Reply #11 on: April 11, 2011, 04:13:31 pm »
I'm new with oop in as3, I've tried following instruction in this topic but I'm not going anywhere.. I still can't interact with swf between pages. I've searched this forum and wiki, still can't found the answer  :-[
Could you give me a complete example of the code with some test case.. or maybe you could share me some link.

Hans Nücke

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 787
  • MegaZine3 Sales Manager
Re: action script interactions between pages
« Reply #12 on: April 11, 2011, 11:55:30 pm »
This topic is about v1.x, and more than 1.5 years old!

I guess you'll intend to use version 2.x?
Then you're totally wrong in this section and should search in posts under version2.x; otherwise you cannot expect things will work if you mix versions...

The wiki is the best place to look for information. It will take some time to understand the structure and to know where to look for what piece of information.
But you'll find out that after you followed some links and got a basic understanding, everything is pretty logical and well structured.

The main page will provide almost all first level links needed; also the one to the API description at http://www.megazine3.de/api2/

Have you ever built a working Mz3 title? Have you read and understood what ASUL is about? Have you built a working set of binaries form the sources? Are you familiar with SVN and ant? Do you understand the plugin concept and have analyzed and understood an existing plugin?
If any of your answers to these questions is a "no", you should perhaps look for other options to learn AS3...