Code to move in the timeline of a SWF background? (1 Viewer)

SyntaxTerror

Content Creator
Joined
Jul 24, 2014
Hello

I am currently working on 16/9 SWF backgrounds for SDT, and I found a trick to move in a wider picture using buttons:

u2m7Fhv.jpg

Basicaly, to have a 16/9 zoomable background for SDT, it has to be 1122x825 px (in fact 1122x600 is a bit wider than 16/9, but it is needed for full screen with window and menu bars, seems complicated but it works).
Here, I am using a 1644x825 px picture, I put its left side touching the left side on frame 1, its right side touching the right side on frame 20, and a classic tween between these two.

Here's the code I am using for buttons:
Code:
stop(); // used to avoid that the frames are automaticaly played

// right button:

right.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);

function fl_ClickToGoToNextFrame(event:MouseEvent):void
{
    nextFrame();
}

// left button:

left.addEventListener(MouseEvent.CLICK, fl_ClickToGoToPreviousFrame);

function fl_ClickToGoToPreviousFrame(event:MouseEvent):void
{
    prevFrame();
}

And here is the FLA of my background mod: HD+ BG test.fla
Along with the SWF if some want to try: HD+ BG test.swf

Actually, I'd prefer to do this using the left and right arrow keys (if they aren't used by another Loader mod in fact), but couldn't manage to find a code or made one myself...

Can someone well versed in ActionScript help me with this code?

Thank you.
 

SyntaxTerror

Content Creator
Joined
Jul 24, 2014
I tried this code that works on a separate "normal" SWF:
Code:
stop();

stage.addEventListener(KeyboardEvent.KEY_DOWN, direction);

function direction(event:KeyboardEvent):void {

    if (event.keyCode==39) {
        nextFrame();
    }
    if (event.keyCode==37) {
        prevFrame();
    }
}
But when I use it SDT template, the background doesn't show...
I think that it is the "stage" on line 3 that is the problem, but I cannot find what could replace it...
 

sby

Content Creator
Coder
Joined
Sep 11, 2012
try using the debugger version of the projector to see any code errors thrown, my loaderpack has a copy
 

SyntaxTerror

Content Creator
Joined
Jul 24, 2014
Mhhh... actually, with the code of my second post, my mod works fine with the Loader but not in Vanilla...
I'd really like to know why and if there is a fix to it, because I try to make all my mods usable with Vanilla.

I think the problem may come from the "stage" thingy, because the background appears (not moving though) if I add a symbol in the Background template , name its instance AAA and replace stage.addEventListener by AAA.addEventListener on line 3.

try using the debugger
I tried using the "play SDT Loader debugmode" shortcut, then opening the debub widow in the Loader tab (I get a see through rectangle at the bottom-right of the screen), but when I launch my mod nothing appears (I am an uber-noob :wat:).

By the way, you say in "about the pack.txt" that "right arrow: clear strands", but I didn't find this shortcut in "Shortcuts.txt". Is there is a way to change this somewhere?
 
Last edited:

sby

Content Creator
Coder
Joined
Sep 11, 2012
Mhhh... actually, with the code of my second post, my mod works fine with the Loader but not in Vanilla...
I'd really like to know why and if there is a fix to it, because I try to make all my mods usable with Vanilla.

I think the problem may come from the "stage" thingy, because the background appears (not moving though) if I add a symbol in the Background template , name its instance AAA and replace stage.addEventListener by AAA.addEventListener on line 3.


I tried using the "play SDT Loader debugmode" shortcut, then opening the debub widow in the Loader tab (I get a see through rectangle at the bottom-right of the screen), but when I launch my mod nothing appears (I am an uber-noob :wat:).

By the way, you say in "about the pack.txt" that "right arrow: clear strands", but I didn't find this shortcut in "Shortcuts.txt". Is there is a way to change this somewhere?
clearallshortcut.txt


"The Stage object is not globally accessible. You need to access it through the stage property of a DisplayObject instance. "


also some code snippets

var SDT = ApplicationDomain.currentDomain;
var g = SDT.getDefinition("g");
g.stageRef //not sure if this is accesable in vanilla
 

SyntaxTerror

Content Creator
Joined
Jul 24, 2014
I tried this:
Code:
var SDT = ApplicationDomain.currentDomain;
var g = SDT.getDefinition("g");

stop();

g.stageRef.addEventListener(KeyboardEvent.KEY_DOWN, direction);

function direction(event:KeyboardEvent):void {

    if (event.keyCode==39) {
        nextFrame();
    }
    if (event.keyCode==37) {
        prevFrame();
    }
}
And I'm getting more and more confused:
This code works for Vanilla, but only if I press one of the buttons I left from my previous version. Until I press this useless button (there is no more code linked to it), the arrow keys do not work.
Also, now the background doesn't appear in the Loader!

For the "not working in Loader issue", maybe there's a way to solve it like in ModGuy's code to change RGB sliders?

These problems with ActionScript are really hard to deal with for me. I know little about this language and I don't know what will work or not with SDT... :rolleyes:
 
Last edited:

sby

Content Creator
Coder
Joined
Sep 11, 2012
here you go:

import SDTMods.*;
import flash.events.KeyboardEvent;
import flash.system.ApplicationDomain;
registerMod(mybackground);
modName = "HD+ BG";
modCreator = "SyntaxTerror";


var g;
var SDT = ApplicationDomain.currentDomain;

try
{
g = SDT.getDefinition("g");
g.stageRef.parent.addEventListener(KeyboardEvent.KEY_DOWN, direction);
}
catch( e)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, direction);
}



function direction(event:KeyboardEvent):void {

if (event.keyCode==39) {
mybackground.nextFrame();
}
if (event.keyCode==37) {
mybackground.prevFrame();
}
}
 

Attachments

HD+ BG test.fla
2.7 MB · Views: 1,345

Users who are viewing this thread

Top


Are you 18 or older?

This website requires you to be 18 years of age or older. Please verify your age to view the content, or click Exit to leave.