Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-13-2012, 08:48 AM   #1
consig1iere
Registered User
 
Join Date: Jun 2012
Posts: 8
Default How to Use this code for several frames?

Hello everyone, I'm completely new to Actionscript, I've searched everywhere for a screen orientation code but couldn't find a proper one. I'm trying to make a book app with several pages (frames) which has both portrait & landscape mode. I found a code written by Adam Khoury but it only works with one frame. Is there any way to use this code with several frames (pages) with different movieclips? Here is a video of him using this code: goo.gl/T24ku. Thanks.

ActionScript Code:
// AS3.0 Android App View Modes Script For App View Orientation // Written by Adam Khoury import flash.display.Stage; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; // Create stage instance and manipulate 2 of its properties var appStage:Stage = myApp.stage; appStage.scaleMode = StageScaleMode.NO_SCALE; appStage.align = StageAlign.TOP_LEFT; // Function that executes each time a phone or device is rotated function orientateMyApp(event:Event):void {     var device_width:int = appStage.stageWidth;     var device_height:int = appStage.stageHeight;     // Condition that allows toggling between view modes     if(device_width > device_height){         myApp.gotoAndStop("wide_view");     } else {         myApp.gotoAndStop("tall_view");     } } // Add an event listener for the resize event of the stage instance appStage.addEventListener(Event.RESIZE, orientateMyApp);
consig1iere is offline   Reply With Quote
Old 07-13-2012, 10:15 AM   #2
santanoa
Dual Screen Empowered
 
santanoa's Avatar
 
Join Date: Jul 2010
Location: Israel
Posts: 258
Default

All you have to do is extend the layer-with-the-code's frame until wherever you want to code to be applicable. The standard way of doing this is by having a dedicated Actionscript layer in your app whose keyframe extends the entire length of the movie, then just put whatever you want in it. It's really MUCH better to put code like this in a class in order to simplify updating and editing later, but that's up to you.

Anyway, I thought I already recommended a place to find screen orientation code (http://www.amazon.com/Professional-F...le+development) which should also help with other aspects of your app, for example, dealing with the much lower memory capacity found on mobile devices.

Good luck
santanoa is offline   Reply With Quote
Old 07-13-2012, 09:17 PM   #3
consig1iere
Registered User
 
Join Date: Jun 2012
Posts: 8
Default

Hey Santanoa, I really appreciate your replies. I haven't got hold of the book yet but I'll definitely take a look. Ok so I did extend the layer-with-the-code's frame but the prob is in AS3 layer on Frame1 code I have several objects (instances?) mentioned that appears in Frame2. That is why I'm getting this error:

Error #1009: Cannot access a property or method of a null object reference.

Is there a way to mention a code in Frame1 and specify it to execute in let's just say Frame2 or whatever Frame?
consig1iere is offline   Reply With Quote
Old 07-14-2012, 05:55 PM   #4
santanoa
Dual Screen Empowered
 
santanoa's Avatar
 
Join Date: Jul 2010
Location: Israel
Posts: 258
Default

There are three ways to do this:

Either check whether you are on frame2 in an enterFrame event:

ActionScript Code:
this.addEventListener(Event.ENTER_FRAME, enterFrame); function(event:Event):void {     if (this.currentFrame() == 2) {         //do whatever     } }

I wouldn't recommend this
You could also check if the object exists before referencing it. For example:

ActionScript Code:
//...random code beforehand if (object) {  //check if object exists     //run code referencing object } else {     trace('object does not exist yet'); } //...random code after


finally you could have a seperate keyframe/layer for the code that runs on frame2 so that it stays only on frame2

Probably the second method is the least clunky.

Hope that helps
santanoa is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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. The time now is 01:57 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.